I believe my earlier answer has value so I am creating a separate one here that addresses this more specific use case. The conditions are:
- cannot control the server
- must limit the file size of the csv's prior to uploading
- the server is not encoding the csv's with gzip
I suggest using the JSXCompressor library to decode gzip files in javascript on the client.
However, the gzip'd files must first be base64 encoded. The following linux command will do this:
gzip -c file.csv | base64 > file.csv.gz.txt
I recommend using the .txt file extension to ensure the server handles it like text.
Since I'm using the DataURI to download the csv (see below), you could also base64 encode it before gzipping to save doing that on the client. However, it increases the file size (which you are trying to avoid).
Once the files are gzip'd & base64'd, then can be uploaded to the server. Note that base64 will add substantial overhead but it is required. It is more pronounced with smaller files:
uncompressed: 91 kB
compressed: 38 kB
compressed + base64: 72 kB
uncompressed: 8.2 MB
compressed: 1.9 MB
compressed + base64: 2.6 MB
Here is the HTML markup. This is a working example that I have tested.
<html>
<head>
<title>Working Example</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="jsxcompressor.min.js" type="text/javascript"></script>
<script type="text/javascript">
$.ajax({
url: "/file.csv.gz.txt",
cache: false
})
.done(function (b64file) {
// $('body').append(b64file); // debug
var binary = JXG.decompress(b64file);
$('#link').attr("href", "data:text/csv;base64," + btoa(binary));
});
</script>
</head>
<body>
<a id="link" download="file.csv">file</a>
</body>
</html>