【问题标题】:InvalidRange error when downloading empty file from Azure File Shares with .NET SDK使用 .NET SDK 从 Azure 文件共享下载空文件时出现 InvalidRange 错误
【发布时间】:2021-09-22 16:19:51
【问题描述】:

我正在尝试使用Azure.Storage.Files.Shares 中提供的工具从 Azure 文件共享下载一个空文件。下载包含超过 0 个字节的文件可以正常工作。但是,在我的集成测试中,我正在创建/下载空文件。对于我的测试来说,只使用填充文件并不是什么大问题,但是在我们的应用程序中意外上传并选择下载一个空文件并不是不合理的。那么问题来了:

我收到 InvalidRange 错误:

Status: 416 (The range specified is invalid for the current size of the resource.)
    ErrorCode: InvalidRange
    
    Content:
    <?xml version="1.0" encoding="utf-8"?><Error><Code>InvalidRange</Code><Message>The range specified is invalid for the current size of the resource.
    RequestId:9f04885b-401a-005e-80fa-77d94a000000
    Time:2021-07-13T15:16:59.9547272Z</Message></Error>
    
    Headers:
    Content-Range: bytes */0
    x-ms-request-id: 9f04885b-401a-005e-80fa-77d94a000000
    x-ms-client-request-id: a6ee7be7-7ae9-4587-b28c-d6a15cd499e8
    x-ms-version: 2020-08-04
    x-ms-error-code: InvalidRange
    Content-Length: 249
    Content-Type: application/xml
    Date: Tue, 13 Jul 2021 15:16:59 GMT
    Server: Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0

我的下载代码是this example code提供的代码:

ShareFileDownloadInfo download = file.Download();
using (FileStream stream = File.OpenWrite(localFilePath))
{
    download.Content.CopyTo(stream);
}

同样,它适用于非空文件。 The documentation for the underlying storage REST API 表示“范围”是一个可选参数,如果留空,默认情况下将下载所有文件内容。我知道可以这样做,因为这些文件可以通过 Azure 门户手动下载。

这是一个错误还是这个下载代码不完整?

【问题讨论】:

标签: c# .net azure azure-storage azure-sdk


【解决方案1】:

【讨论】:

    【解决方案2】:

    在等待修复错误时(可能需要一段时间),您始终可以在尝试下载之前检查文件的 ContentLength。

    ShareFileProperties properties = file.GetProperties();
    if (properties.ContentLength > 0)
    {
        ShareFileDownloadInfo response = file.Download();
        response.Content.CopyTo(myStream);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-10-11
      • 2021-12-06
      • 2013-05-08
      • 1970-01-01
      • 2019-04-28
      • 1970-01-01
      • 2023-03-31
      相关资源
      最近更新 更多