4
我想gzip并上传一个静态js文件到Azure blob,但我最终得到一个0字节的blob。有人能告诉我我做错了什么吗?Gzip并上传到Azure blob
var filePath = "C:\test.js";
using (var compressed = new MemoryStream()) {
using (var gzip = new GZipStream(compressed, CompressionMode.Compress)) {
var bytes = File.ReadAllBytes(filePath);
gzip.Write(bytes, 0, bytes.Length);
var account = CloudStorageAccount.Parse("...");
var blobClient = new CloudBlobClient(account.BlobEndpoint, account.Credentials);
var blobContainer = blobClient.GetContainerReference("temp");
var blob = blobContainer.GetBlockBlobReference(Path.GetFileName(filePath));
blob.Properties.ContentEncoding = "gzip";
blob.Properties.ContentType = "text/javascript";
blob.Properties.CacheControl = "public, max-age=3600";
blob.UploadFromStream(compressed);
}
}
在发布有关Storage客户端的问题时,包含您正在使用的存储库的版本会非常有帮助。版本之间有差异。 – MikeWo