将单个文件上传到 Blob 存储 Azure [英] Upload a Single File to Blob Storage Azure

查看:49
本文介绍了将单个文件上传到 Blob 存储 Azure的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 C# 上传文件?我需要从 dialogWindow 上传文件.

How can I to Upload a file with C# ? I need to upload a file from a dialogWindow.

推荐答案

using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Auth;
using Microsoft.WindowsAzure.Storage.Blob;    

// Retrieve storage account from connection string.
    CloudStorageAccount storageAccount = CloudStorageAccount.Parse("StorageKey");

// Create the blob client.
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

// Retrieve reference to a previously created container.
CloudBlobContainer container = blobClient.GetContainerReference("mycontainer");

// Retrieve reference to a blob named "myblob".
CloudBlockBlob blockBlob = container.GetBlockBlobReference("myblob");

// Create or overwrite the "myblob" blob with contents from a local file.
using (var fileStream = System.IO.File.OpenRead(@"pathmyfile"))
{
    blockBlob.UploadFromStream(fileStream);
}

请参阅此处 关于需要的 SDK 和参考

see here about needed SDK and references

我认为这是你需要的

这篇关于将单个文件上传到 Blob 存储 Azure的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆