【发布时间】:2016-10-01 09:19:40
【问题描述】:
我正在尝试使用 WindowsAzure.Storage 7.0.2-preview 将图像流从 Xamarin.Forms PCL 应用程序上传到 Azure Blob。出于某种原因,StorageCredentials 无法识别 SAS 令牌的 AccountName。
var credentials = new StorageCredentials("https://<ACCOUNT-NAME>.blob.core.windows.net/...");
CloudStorageAccount Account = new CloudStorageAccount(credentials, true);
然后像这样上传:
public async Task<string> WriteFile(string containerName, string fileName, System.IO.Stream stream, string contentType = "")
{
var container = GetBlobClient().GetContainerReference(containerName);
var fileBase = container.GetBlockBlobReference(fileName);
await fileBase.UploadFromStreamAsync(stream);
if (!string.IsNullOrEmpty(contentType))
{
fileBase.Properties.ContentType = contentType;
await fileBase.SetPropertiesAsync();
}
return fileBase.Uri.ToString();
}
如何解决我的问题?有没有更好的上传到 Azure 存储的解决方案? 谢谢!
【问题讨论】:
-
您遇到了什么特定错误或异常?
-
@Jason 错误是:值不能为空。参数名称:AccountName
-
您是否尝试过只使用您的帐户名称而不是网址?
-
@Jason 是的,它抛出了同样的异常。
标签: xamarin xamarin.forms azure-storage