且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何向Azure存储Blob上传添加身份验证

更新时间:2023-02-15 15:49:42

如果有权访问Azure门户,则可以获取存储帐户的连接字符串(在访问密钥"部分下).

If you have access to the Azure Portal, you can get the connection string of the storage account (under "Access Keys" section).

一旦有了连接字符串,就可以使用以下代码:

Once you have the connection string, you can use the following code:

var connectionString = "your-storage-account-connection-string";
var containerName = "images";
var blobName = "myfile.png";

var blobClient = new BlobClient(connectionString, containerName, blobName);
//do the upload here...

其他选项是使用存储帐户名和访问密钥(同样,您可以从Azure门户获取它).您将执行以下操作:

Other option is to use storage account name and access key (again you can get it from Azure Portal). You would do something like:

var accountName = "account-name";
var accountKey = "account-key";
var blobUri = new Uri("https://mystorageaccount.blob.core.windows.net/images/myfile.png");
var credentials = new StorageSharedKeyCredential(accountName, accountKey);
var blobClient = new BlobClient(blobUri, credentials);
//do the upload here...

您可以在此处找到有关BlobClient构造函数的更多信息: https://docs.microsoft.com/zh-cn/dotnet/api/azure.storage.blobs.blobclient?view=azure-dotnet .

You can find more information about BlobClient constructors here: https://docs.microsoft.com/en-us/dotnet/api/azure.storage.blobs.blobclient?view=azure-dotnet.