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