c# - Azure 文件存储 云文件

标签 c# azure azure-storage azure-storage-files

我正在尝试以编程方式下载刚刚保存到 Azure 文件存储中的文件,并且我收到了

{"The remote server returned an error: (400) Bad Request."}

当我调用 DownloadToStream 方法时。做错了什么?
任何帮助将不胜感激。谢谢!

这是代码:

        var combinedRelativeDirectory = GetCloudDirectory(relativePath);
        CloudFile cloudFile = null;

        cloudFile = combinedRelativeDirectory.GetFileReference(filename);
        var memoryStream = new MemoryStream();

        cloudFile.DownloadToStream(memoryStream, AccessCondition.GenerateIfExistsCondition());
        memoryStream.Position = 0;
        return memoryStream;

最佳答案

我可以使用您的代码重现您的问题。通过查看Fiddler的响应消息。我发现详细错误消息是“不支持条件 header 。”。删除AccessCondition.GenerateIfExistsCondition()参数后,代码可以正常工作。

cloudFile.DownloadToStream(memoryStream);

如果您想在下载文件之前检查文件是否存在,可以使用 Exists 方法。

if (file.Exists())
{
    file.DownloadToStream(memoryStream);
}

关于c# - Azure 文件存储 云文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44641500/

相关文章:

c# - 在不公开 ORM 模型的情况下使用 OData 进行查询?

python - 无法使用 Python 创建 Azure 表

azure - 复制 Azure Blob 并注入(inject) Azure 媒体服务会产生 System.Data.Services.Client.DataServiceQueryException

c# - EF Core 中的数据库资源授权

c# - Windows 8 中的墙纸注册表项在哪里?

spring - Jedis连接异常: Could not get a resource from the pool

.net - 如何上传到 Azure Blob 存储而不覆盖?

Azure 存储模拟器将数据存储在特定路径上

c# - 为什么 C# 中的 Rectangle 类没有 Center() 方法?

asp.net-mvc-3 - Azure 中的 MVC3 EF 应用程序,为什么我必须每隔一段时间预热一次?