Azure:下载上传到azure blob存储的文件时大小为0且编码错误

时间:2016-11-12 14:51:12

标签: azure azure-storage azure-storage-blobs

我需要使用blob uri从temp blob读取文件并写入其他blob。 我可以下载和上传文件,但文件大小在存储资源管理器中显示为0,如果我尝试从资源管理器中打开/下载获取编码错误。

我的代码

StorageCredentials storageCredentials = new StorageCredentials("AccountName", "Accountkey");

CloudBlockBlob blob = new CloudBlockBlob(new Uri(message), storageCredentials);

blob.Properties.ContentType = "application/pdf";

using (MemoryStream ms = new MemoryStream())

{

blob.DownloadToStream(ms);

CloudStorageAccount storageAccount = CloudStorageAccount.Parse(AzureStorageConnectionString);

CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

CloudBlobContainer container = blobClient.GetContainerReference("BlobPDF");

CloudBlockBlob targetblob = container.GetBlockBlobReference("test123.pdf");

targetblob.Properties.ContentType = "application/pdf";  

targetblob.UploadFromStream(ms);

}

1 个答案:

答案 0 :(得分:0)

我很确定你必须"倒带"你的记忆:ms.Position = 0;
uploading to azure storage from memorystream returning an empty file