【发布时间】:2016-04-14 13:16:23
【问题描述】:
我正在尝试使用 CloudFileClient 简单地上传文件,但遇到了一个奇怪的响应。我直接从 SDK 附带的 Azure 示例文件存储项目中获取示例代码。
我的代码执行完全相同的步骤:
string connection = CloudConfigurationManager.GetSetting("AzureFileStorage");
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connection);
// Create a CloudFileClient object for credentialed access to File storage.
CloudFileClient fileClient = storageAccount.CreateCloudFileClient();
// Get a reference to the file share we created previously.
CloudFileShare share = fileClient.GetShareReference("documents");
await share.CreateIfNotExistsAsync();
// Get a reference to the root directory of the share.
CloudFileDirectory root = share.GetRootDirectoryReference();
// Put files in this user's folder
CloudFileDirectory dir = root.GetDirectoryReference(User.Identity.GetUserId());
await dir.CreateIfNotExistsAsync();
// Save the document to Azure File Storage
if (System.IO.File.Exists(model.DocumentPath))
{
CloudFile file = dir.GetFileReference(model.DocumentPath);
await file.UploadFromFileAsync(model.DocumentPath, FileMode.Open);
}
最后一行返回 400 错误请求。我在我的 Azure 门户中检查子目录已成功创建,并且我可以通过 azure 门户手动上传文件,但是当我尝试示例代码并且我知道文件路径良好时,异步调用总是给我一个黄色带有 400 的页面。
我没有使用日期时间,我的容器名称不是以大写字母开头,我要上传的文件只有几 K
CloudFile 中的 Storage Uri 是 StorageUri {Primary = 'https://mydomain.file.core.windows.net/documents//C:%5Cdev%5Creadme.txt';次要 = ''}
【问题讨论】:
标签: .net azure model-view-controller cloud storage