Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

456
Visualizações
InvalidRange error when downloading empty file from Azure File Shares with .NET SDK

I am trying to download an empty file from an Azure File Share with the tools provided in Azure.Storage.Files.Shares. Downloading a file which contains more than 0 bytes works fine. However, in my integration tests, I am creating/downloading empty files. For my tests it's not a big deal to just use populated files, but it's not unreasonable that an empty file could be accidentally uploaded and chosen for download in our application. So here's the problem:

I am getting an InvalidRange error:

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

My download code is the code provided in this example code:

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

Again, it works fine for files that aren't empty. The documentation for the underlying storage REST API says that 'Range' is an optional parameter that, when left empty, will download all of the file content by default. I know it's possible to do because the files are downloadable manually through the Azure Portal.

Is this a bug or is this download code incomplete?

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

Confirmed as a bug. Track here https://github.com/Azure/azure-sdk-for-net/issues/22616

over 4 years ago · Santiago Trujillo Relatório

0

While waiting for the bug to be fixed (which can take a while) you can always check the ContentLength of the file before attempting a download.

ShareFileProperties properties = file.GetProperties();
if (properties.ContentLength > 0)
{
    ShareFileDownloadInfo response = file.Download();
    response.Content.CopyTo(myStream);
}
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda