Reputation: 351
I am trying to set the properties for a thumbnail I upload to the Blob Service.
CloudBlockBlob blockBlob = container.GetBlockBlobReference(Guid.NewGuid().ToString().Replace("-", "") + ".jpg");
bytes = thumbnailStream.ToArray();
await blockBlob.UploadFromByteArrayAsync(bytes, 0, bytes.Length);
blockBlob.Properties.ContentType = "image/jpeg";
blockBlob.Properties.CacheControl = "public, max-age=172800";
await blockBlob.SetPropertiesAsync();
return blockBlob.Uri.ToString();
The headers I receive in the browser are as follows:
Content-Length:0
Date:Sun, 07 Feb 2016 11:51:11 GMT
Server:Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0
x-ms-request-id:5f77d341-0001-00ef-759d-61c590000000
x-ms-version:2009-09-19
Am I doing something wrong or is it a bug?
Upvotes: 0
Views: 247
Reputation: 136196
Neither you're doing anything wrong nor it is a bug. Essentially these are the response headers for Set Blob Properties
operation, which gets performed when the following line of code is executed:
await blockBlob.SetPropertiesAsync();
I also noticed that your code is not optimal and can be improved. Essentially you're doing 2 network operations - First to upload the blob and second to set the properties of the blob. You can combine them in a single operation just by changing few lines of code:
CloudBlockBlob blockBlob = container.GetBlockBlobReference(Guid.NewGuid().ToString().Replace("-", "") + ".jpg");
bytes = thumbnailStream.ToArray();
blockBlob.Properties.ContentType = "image/jpeg";
blockBlob.Properties.CacheControl = "public, max-age=172800";
await blockBlob.UploadFromByteArrayAsync(bytes, 0, bytes.Length);
return blockBlob.Uri.ToString();
Above lines of code will not only upload the blob but also set the properties of it in a single network call. Also in this case if you look at response headers, you will see blob's content length and other blob properties being returned.
Upvotes: 2