我将流用于文件和:内存流、流读取或文件流,例如
byte[] buff = System.IO.File.ReadAllBytes(open.FileName);
System.IO.MemoryStream ms = new System.IO.MemoryStream(buff);我想把它发送到blob存储,此时我的blob是空的,是因为逐流读取文件,还是因为它引用了其他问题,比如blob或CloudStorageAccount连接字符串上的错误配置。
发布于 2015-12-28 09:16:29
只需使用下面的代码。不需要转换内存流,您可以使用Blob.UploadfromStream方法将流传递到blob存储。
StorageCredentials creds = new StorageCredentials(
ConfigurationManager.AppSettings["accountName"],
ConfigurationManager.AppSettings["accountKey"]
);
CloudStorageAccount account = new CloudStorageAccount(creds, useHttps: true);
CloudBlobClient client = account.CreateCloudBlobClient();
CloudBlobContainer contain = client.GetContainerReference("your container name");
contain.CreateIfNotExists();
CloudBlockBlob blob = contain.GetBlockBlobReference("your blob name");
using (var stream = System.IO.File.OpenRead("your file"))
blob.UploadFromStream(stream);发布于 2015-12-28 07:57:08
在开始从该流上传到blob之前,请确保您的流位于0。正如在上面的注释中所提到的,您可以尝试以下方法:
ms.Position = 0或
ms.Seek(0, SeekOrigin.Begin)https://stackoverflow.com/questions/34474850
复制相似问题