Azure:下载上传到 Azure Blob 存储的文件时出现大小 0 和编码错误

Azure: size 0 and encoding error while downloading the file uploaded to azure blob storage

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

我的代码

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);

}

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