Uploading blockblob and setting contenttype

后端 未结 6 1108
旧巷少年郎
旧巷少年郎 2020-12-15 16:20

I\'m using Microsoft.WindowsAzure.Storage.* library from C#.

This is how I\'m uploading things to storage:

// Store in storage
CloudStor         


        
6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-15 16:53

    Obviously best to set it on create like Gaurav Mantri's answer, if you are past that point and need to update the other answers here may mess you up.

    // GET blob
    CloudBlobContainer container = blobClient.GetContainerReference(containerName);
    CloudBlockBlob blockBlob = container.GetBlockBlobReference(fileName); 
    
    // if you don't do this you'll wipe properties you didn't mean to
    await blockBlob.FetchAttributesAsync();
    
    // SET
    blockBlob.Properties.ContentType = mimetype;
    
    // SAVE
    await blockBlob.SetPropertiesAsync();
    

提交回复
热议问题