Hi, Tim Roberts!
Currently I stuck in p.5 of https://msdn.microsoft.com/en-us/library/windows/hardware/dn800660.aspx. After I send UpdateComplete I always get 404. On dashboard I see a new submission without package.
Can someone from MS review it?
source:
static void UploadFile(string sasUrl, string filepath, string SessionGuid)
{
Console.WriteLine(“Uploadfile:\n {0}\n {1}\n {2}\n”, filepath, sasUrl, SessionGuid);
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Add(“x-ms-version”, “2013-08-15”);
client.DefaultRequestHeaders.Add(“x-ms-client-request-id”, SessionGuid);
StringBuilder sb = new StringBuilder(“<?xml version=\"1.0\" encoding=\"utf-8\"?>”);
int bytesRead = 0;
int Offset = 0;
// Read the source file into a byte array.
byte bytes = new byte[1024 * 1024];
FileStream SourceStream = new FileStream(filepath, FileMode.Open, FileAccess.Read);
bytesRead = GetFileChunks(SourceStream, Offset, ref bytes);
while (bytesRead > 0)
{
string blockid = GetHash(bytes);
HttpRequestMessage chunkMessage = new HttpRequestMessage()
{
Method = HttpMethod.Put,
RequestUri = new Uri(sasUrl + “&timeout=90&comp=block&blockid=” + WebUtility.UrlEncode(blockid)),
Content = new ByteArrayContent(bytes)
};
chunkMessage.Headers.Add(“x-ms-blob-type”, “BlockBlob”);
chunkMessage.Content.Headers.Add(“Content-MD5”, blockid);
Console.WriteLine(“Uploading chunk {0}\n”, blockid);
// TimeAction(“Uploading chunk " + blockid + " took {0} ms”, () =>
{
var response = client.SendAsync(chunkMessage).Result;
Console.WriteLine(“{0} ({1})”, (int)response.StatusCode, response.ReasonPhrase);
}
// );
sb.Append(“”);
sb.Append(blockid);
sb.Append(“”);
Offset = Offset + bytesRead;
bytesRead = GetFileChunks(SourceStream, Offset, ref bytes);
}
sb.Append(“”);
Console.WriteLine(“{0}\n”, sb.ToString());
HttpRequestMessage commitMessage = new HttpRequestMessage()
{
Method = HttpMethod.Put,
RequestUri = new Uri(sasUrl + “&timeout=90&comp=blocklist”),
Content = new StringContent(sb.ToString())
};
Console.WriteLine(“Committing the blocks…\n”);
// TimeAction(“Commiting the blocks took {0} ms”, () =>
{
var commit = client.SendAsync(commitMessage).Result;
Console.WriteLine(“{0} ({1})”, (int)commit.StatusCode, commit.ReasonPhrase);
}
// );
}
}
private static string GetHash(byte bytes)
{
string hash;
using (MD5 md5Hash = MD5.Create())
{
hash = Convert.ToBase64String(md5Hash.ComputeHash(bytes));
}
return hash;
}
private static int GetFileChunks(FileStream SourceStream, int offset, ref byte buf)
{
try
{
// Read the source file into a byte array.
int numBytesToRead = (int)1024 * 1024;
// Read may return anything from 0 to numBytesToRead.
return SourceStream.Read(buf, offset, numBytesToRead);
}
catch (SystemException ioEx)
{
Console.WriteLine(ioEx.Message);
}
return 0;
}