You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
how to turn off automatic decompression when download gzipped file #509
when use the following to download gzipped file, The download works but Azure or the SDK decompresses my gzipped files on the fly when the files are fetched.
how can I turn off this behavior? thanks
Hi imeya, you could do a get blob properties call with any SDK. You could also use the Storage Explorer either on the portal or on the desktop; do a right click on your blob and then select properties; finally scroll to the bottom to see the Content-type and Content-encoding .
Hi imeya, I did some digging and here's an update:
When the Content-Encoding header is set to gzip (by the user who uploaded the blob, there is no default value), the requests module would decode it automatically, which is the expected behavior.
If you have control over the data, I think the easiest way to fix this problem is to not set the Content-Encoding in the blobs' properties. If you cannot do that, then it's a bit more work to prevent the body from being decoded.
One way to do that is to replace the _http_client that the BlockBlobService uses to perform HTTP requests. Currently, it reads the body by calling response.content which decodes the body. Here is an explanation on how to read the raw data instead.
Here is a an example:
fromazure.storage.common._http.httpclientimport (
_HTTPClient,
HTTPResponse,
)
fromazure.storage.common._serializationimport_get_data_bytes_or_stream_onlyimportrequestsclassExampleRawBodyReadingClient(_HTTPClient):
defperform_request(self, request):
''' Sends an HTTPRequest to Azure Storage and returns an HTTPResponse. If the response code indicates an error, raise an HTTPError. :param HTTPRequest request: The request to serialize and send. :return: An HTTPResponse containing the parsed HTTP response. :rtype: :class:`~azure.storage.common._http.HTTPResponse` '''# Verify the body is in bytes or either a file-like/stream objectifrequest.body:
request.body=_get_data_bytes_or_stream_only('request.body', request.body)
# Construct the URIuri=self.protocol.lower() +'://'+request.host+request.path# Send the requestresponse=self.session.request(request.method,
uri,
params=request.query,
headers=request.headers,
data=request.bodyorNone,
timeout=self.timeout,
proxies=self.proxies,
stream=True)
# Parse the responsestatus=int(response.status_code)
response_headers= {}
forkey, nameinresponse.headers.items():
# Preserve the case of metadataifkey.lower().startswith('x-ms-meta-'):
response_headers[key] =nameelse:
response_headers[key.lower()] =namewrap=HTTPResponse(status, response.reason, response_headers, response.raw.read())
response.close()
returnwrap
The important part to note is that I added stream=True to the call self.session.request, and also used response.raw.read() instead of response.content when creating a HTTPResponse.
I verified that the file downloaded this way has the right content, by computing its MD5 and comparing against the gzipped file. Please let me know if you have any question.
Activity
zezha-msft commentedon Oct 10, 2018
Hi imeya, thanks for reaching out!
I've seen a similar issue in the past, I'll investigate and let you know. Thanks!
imeya commentedon Oct 22, 2018
Ze Qian Zhang (@zezha-msft) , any feedback?
zezha-msft commentedon Oct 22, 2018
Hi imeya, sorry for the delay.
Could you please confirm with me what was the Content-type and Content-encoding of your blob?
imeya commentedon Oct 23, 2018
how can I check that in azure portal -> blob storage? I have checked the blob property from portal, but no such property you mentioned.
zezha-msft commentedon Oct 23, 2018
Hi imeya, you could do a
get blob propertiescall with any SDK. You could also use the Storage Explorer either on the portal or on the desktop; do a right click on your blob and then selectproperties; finally scroll to the bottom to see the Content-type and Content-encoding .zezha-msft commentedon Oct 25, 2018
Hi imeya, I did some digging and here's an update:
When the Content-Encoding header is set to
gzip(by the user who uploaded the blob, there is no default value), therequestsmodule would decode it automatically, which is the expected behavior.If you have control over the data, I think the easiest way to fix this problem is to not set the Content-Encoding in the blobs' properties. If you cannot do that, then it's a bit more work to prevent the body from being decoded.
One way to do that is to replace the _http_client that the BlockBlobService uses to perform HTTP requests. Currently, it reads the body by calling
response.contentwhich decodes the body. Here is an explanation on how to read the raw data instead.Here is a an example:
The important part to note is that I added
stream=Trueto the callself.session.request, and also usedresponse.raw.read()instead ofresponse.contentwhen creating aHTTPResponse.I tested it with the following code:
I verified that the file downloaded this way has the right content, by computing its MD5 and comparing against the gzipped file. Please let me know if you have any question.
SNOW-116535: fix GET command for Azure for workaround Azure/azure-sto…
SNOW-116535: fix GET command for Azure for workaround Azure/azure-sto…
SNOW-116535: fix GET command for Azure for workaround Azure/azure-sto…