Share via

Downloading a zero-sized blob with a range header specified

John Doe 0 Reputation points
2025-06-25T13:05:13.6133333+00:00

In my latency-sensitive use case, I try to retrieve blob metadata and its contents whenever the length of the latter meets a certain threshold. To that end, I perform a Get Blob operation on the target blob, setting the Range header to say the value bytes 0-500. This works well with nonempty blobs, but fails as soon as an empty blob appears - the service responds with an HTTP 416 error code and does not provide any metadata for the target blob - neither the version id, nor the etag.

One possible solution is to perform a Get Blob Properties operation, followed by a Get Blob against the target blob, passing along the etag and version id properties. However, this would affect the vast majority of time-sensitive operations.

As an alternative, this fallback flow can be implemented for the HTTP 416 error response cases, but it works poorly if an empty blob changes between calls.

So, does Azure Blob provide a way to handle the described scenario uniformly, within a single call, without resorting to the aforementioned hacks?

Azure Blob Storage
Azure Blob Storage

An Azure service that stores unstructured data in the cloud as blobs.


1 answer

Sort by: Most helpful
  1. Anonymous
    2025-06-25T15:38:36.26+00:00

    Hello John Doe,

    Thank you for your question!

    You are encountering the "HTTP 416 ErrorCode: Requested Range Not Satisfiable" because Azure Blob Storage does not support retrieving a byte range from an empty blob. When you issue a Get Blob request with a Range header (e.g., bytes=0-500) on a blob with zero bytes, the service cannot fulfill the request and returns a 416 error.

    Critically, this response does not include any metadata such as ETag, VersionId, or custom properties, which are typically returned for non-empty blobs. This limitation becomes problematic in latency-sensitive applications where both metadata and partial content are needed in a single call.

    Azure Blob Storage does not currently offer a built-in mechanism to handle this scenario uniformly. The recommended approach is to first perform a Get Blob Properties operation to retrieve the blob’s metadata and determine its size.

    If the Content-Length is greater than zero, you can then proceed with a Get Blob request using the desired Range header. This two-step process ensures that you avoid 416 errors and always retrieve metadata, though it introduces a slight increase in latency.

    To mitigate this, consider tagging blobs during upload to indicate whether they are empty, allowing your application to skip unnecessary range requests. Alternatively, implement event-driven monitoring (e.g., using Azure Event Grid) to track blob changes and maintain an up-to-date state. While this approach adds some complexity, it provides a reliable and performant way to handle both empty and non-empty blobs consistently.

    Reference:

    Hope the above answer helps! Please let us know do you have any further queries.


    Please do not forget to "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community membersUser's image

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.