empty image from blob storage

↘锁芯ラ 提交于 2019-12-02 09:25:25

问题


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.

From danish to english: We can not open this file

回答1:


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.

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.

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


来源:https://stackoverflow.com/questions/48664217/empty-image-from-blob-storage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!