title: How to upload a file directly to azure blob from the URL in c#?
body: <p>I have a url which looks like following &quot;https://XXXXXXXX-functions.azurewebsites.net/api/UploadedZIPFile?ticket=1234&amp;code=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&quot; which contains the file. &quot;UploadedZIPFile&quot; is the file Name. In URL I don't have the extension of filename. After downloading the file into my system it is showing the extension. I want to upload the file which came from the URL into Azure blob storage. How can I upload the file to azure blob storage from the given URL using c#? Please Added my code sample below</p>
  <pre><code>public async Task&lt;string&gt; automaticFileUpload(string ticketNum, string type, string fileURL) 
          {
              Uri uri = new Uri(fileURL);
              string fileName = System.IO.Path.GetFileName(uri.LocalPath);
              string extension = &quot;.zip&quot;;
              string finalFileName = fileName + extension;
  
              
  
              var connectionString = &quot;xxxxxxx&quot;;
  
              CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString);
  
              CloudBlobClient cloudBlobClient = storageAccount.CreateCloudBlobClient();
              CloudBlobContainer cloudBlobContainer =
                  cloudBlobClient.GetContainerReference(&quot;xxxxxxx&quot;);
              await cloudBlobContainer.CreateIfNotExistsAsync();
              BlobContainerPermissions permissions = new BlobContainerPermissions
              {
                  PublicAccess = BlobContainerPublicAccessType.Blob
              };
              await cloudBlobContainer.SetPermissionsAsync(permissions);
              if (!cloudBlobContainer.GetPermissionsAsync().Equals(BlobContainerPublicAccessType.Off))
              {
                  await cloudBlobContainer.SetPermissionsAsync(new BlobContainerPermissions
                  {
                      PublicAccess = BlobContainerPublicAccessType.Off
                  });
              }
  
              CloudBlockBlob blockblob = cloudBlobContainer.GetBlockBlobReference(finalFileName);
              blockblob.Properties.ContentType = &quot;application/zip&quot;;
  
              using (var client = new HttpClient())
              {
                  //get the url 
                  var request = new HttpRequestMessage(HttpMethod.Get, fileURL);
                  var sendTask = client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead);
                  var response = sendTask.Result;
  
                  HttpStatusCode status = response.StatusCode;
                  if (status == HttpStatusCode.OK)
                  {
                      var httpStream = response.Content.ReadAsStreamAsync().Result;
                      MemoryStream ms = new MemoryStream();
                      httpStream.CopyTo(ms);
                      ms.Position = 0;
                      await blockblob.UploadFromStreamAsync(ms);
                     
                      return blockblob.Uri.AbsoluteUri;
                  }
              }
  
              return null;
   }
  </code></pre>
  <p>As of now I am taking hard coded values for file extension and content type But I need dynamic values</p>
  <p>Thanks in Advance</p>