I try to upload pictures on azure blob storage and I m having great difficulties to accomplish it.
I'am using the code below to upload :
public static void Upload(this Stream payLoad, string uri)
{
var webRequest = (HttpWebRequest)WebRequestCreator.ClientHttp.Create(new Uri(uri));
webRequest.Method = "PUT";
webRequest.ContentLength = payLoad.Length;
var state = new HttpWebRequestAsyncState<Stream>() { HttpWebRequest = webRequest, PayLoad = payLoad };
Task.Factory.FromAsync<Stream>(
webRequest.BeginGetRequestStream,
webRequest.EndGetRequestStream, state)
.ContinueWith(t1 =>
{
var asyncState1 = (HttpWebRequestAsyncState<Stream>)t1.AsyncState;
using (var requestStream = t1.Result)
{
int bytesRead = 0;
byte[] buffer = new Byte[4096];
while ((bytesRead = asyncState1.PayLoad.Read(buffer, 0, buffer.Length)) != 0)
{
requestStream.Write(buffer, 0, bytesRead);
requestStream.Flush();
}
}
Task.Factory.FromAsync<WebResponse>(
asyncState1.HttpWebRequest.BeginGetResponse,
asyncState1.HttpWebRequest.EndGetResponse,
asyncState1)
.ContinueWith(t2 =>
{
var asyncState2 = (HttpWebRequestAsyncState<Stream>)t2.AsyncState;
if (asyncState2.PayLoad != null)
{
asyncState2.PayLoad.Close();
}
using (var responce = t2.Result)
{
if (responce != null) responce.Close();
}
});
});
}
When I run this code on my developpement machine (vmware with windows 2008 R2 64bit) I get a plugin crash, when I call that in a loop, with no information that I can use at my level.
When I run this code on my personal box windows 7 ultimate 64bit some files get uploaded some don't and have a status in fiddler : Session was aborted by the client, Fiddler, or the Server.
The code that call this is:
private void FileUploadButton_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog() { Multiselect = true, Filter = "Image files (*.jpg)|*.jpg" };
if (ofd.ShowDialog() != true) return;
foreach (var file in ofd.Files)
{
string uri = "http://xxxx.blob.core.windows.net/test/" + file.Name + "?sr=c&si=dev&sig=%2FIKx1NhY8FzgYge7XXXXXXXXXXXXXXXXXXX";
file.OpenRead().Upload(uri);
}
}
Does someone see what I m doing wrong?
Thank you by advance
The issue seems to be related to kaspersky internet security. When disable it, it works.