I am in need of downloading a file from a device. Sometimes, the file might have an incorrect content-encoding
, specifically being encoded as "gzip" when it is not actually compressed in any way.
When the file is properly gzipped, retrieving the content using a basic ajax GET request is straightforward:
$.ajax({
url: 'http://' + IP + '/test.txt',
type: 'GET'
})
.done(function(data) {
alert(data);
});
However, this method fails when the content-encoding is incorrect.
Just to clarify, I am not seeking a workaround for the ERR_CONTENT_DECODING_FAILED
error that may occur when accessing the URL directly in a browser. My goal is to be able to load a csv file, for example, into a JavaScript string for further parsing.
Is there a way to fetch the file and prevent automatic decoding, or to override the content-encoding of the response in some manner?