Reputation: 105
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?
Upvotes: 0
Views: 624
Reputation: 24569
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();
}
Upvotes: 0
Reputation: 26298
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);
}
Upvotes: 1