问题描述
这是我尝试将图像上传到Azure博客存储,然后上传在那里的空文件的方法.
This is how I try to upload an image to Azure blog storage, then upload an empty file located there.
我尝试在此处上传此图片:
I try to upload this image here:
CloudStorageAccount storageAccount = new CloudStorageAccount(new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials(Accountname, KeyValue), true);
// Create the blob client.
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
// Retrieve a reference to a container.
CloudBlobContainer container = blobClient.GetContainerReference(ContainerValue);
CloudBlockBlob blockBlob = container.GetBlockBlobReference(filename);
using (var f = System.IO.File.Open(model.FileToUpload.FileName, FileMode.Create))
{
await blockBlob.UploadFromStreamAsync(f);
}
但是,如果我尝试打开此图像,请说这个.
But if i try to open this image say this.
从丹麦语到英语:我们无法打开此文件
推荐答案
正如Marco所说,FileMode.Create指定操作系统应创建一个新文件.如果该文件已经存在,则将被覆盖.有关更多详细信息,您可以参考此文章.
As Marco said, FileMode.Create specifies that the operating system should create a new file. If the file already exists, it will be overwritten.For more details, you could refer to this article.
根据您提供的图片,斑点大小为 0 B .因此,您将永远找不到文件并打开它.FileMode指定操作系统应如何打开文件.
According to the pictures you provided, your blob size is 0 B. So, you would always couldn't find the file and open it.FileMode specifies how the operating system should open a file.
因此,我建议您可以删除它,并使用 OpenRead 打开现有文件进行读取.您可以参考以下代码:
So I suggest that you could delete it and use OpenRead to open an existing file for reading. You could refer to the code as below:
using (var f = System.IO.File.OpenRead(model.FileToUpload.FileName))
{
await blockBlob.UploadFromStreamAsync(f);
}
这篇关于Blob存储中的空白图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!