如何设置 blob 属性并将内容作为一个请求上传

How to set blob properties and upload content as one request

当您有 CloudBlockBlob blob 时,您可以上传一些内容,例如

blob.UploadText("content");

这将生成一个 http 操作来完成该操作。但是如果我也想设置内容类型,我还需要

blob.Properties.ContentType = "text/plain";
blob.SetProperties();

这会产生另一个 http 操作来设置该内容类型。

尽管每次操作的 azure 定价非常小,但从长远来看 运行 这似乎很浪费(并且由于多次往返而缓慢)。有什么方法可以将属性和内容设置为一次操作吗?

只需在调用 UploadText 之前设置属性即可。所以你的代码将是:

blob.Properties.ContentType = "text/plain";
blob.UploadText("content");