0
votes

I have to upload a file to Listen360 through webclient but my file is stored in Azure blob storage. When I give URL of saved file in blob storage as the path, it gives "URI formats are not supported."

UploadFile(URI, filename)

It work when I give a local path to filename but not for blob storage url of stored file.

Any suggestions?

2
Not sure what UploadFile() is. But... blobs are not the same as local files - you cannot use standard I/O libraries with blobs. Can you please edit your question to be more specific where you're passing the URL to UploadFile()? (meaning... are you passing a blob url as the filename parameter?)David Makogon
Edited the question and I need to pass blob url as a filename.Rushan
Do you have any updates about this thread?Tom Sun - MSFT

2 Answers

1
votes

You probably want to download the file locally, and dump it in to temp folder, then delete it, assuming that's the only way you can do it.

string fileName = Path.GetTempPath() + Guid.NewGuid().ToString() + ".xml";

using(var client = new WebClient ())
{
   client.DownloadFile(blob.URL, fileName);

   UploadFile(fileName, "mystuff.xml");
   File.Delete(fileName);
}
0
votes

WebClient.UploadFile just allows to upload the specified local file to a resource with the specified URI. We can use stream to upload the file to a resource. The following is my sample demo code. It works correctly for me.

       using (var client = new WebClient())
       {
           var download = client.DownloadData("blob url");
           client.Credentials = new NetworkCredential(@"userName","password");// Some code for authenticating
           var clientStream =client.OpenWrite(new Uri("your Url"));
           clientStream.Write(download, 0, download.Length);
           clientStream.Close();
       }