Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

449
Vistas
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 Respuestas
Responde la pregunta

0

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

over 4 years ago · Santiago Trujillo Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda