Im pretty new to AWS and MeteorJ and I'm having issue downloading large files (100mb+). I would like the user to click the download button and the file start downloading right away. I might be wrong but the code looks like is downloading the file into memory and then sending it to the client-side.
EDIT: The question is a bit different. I'm not calling the server function via http. I added the call to the server.
Here is the call to the server:
function getFile(data) {
const def = $q.defer();
Meteor.call('downloadFileFromS3', data, (err, res) => {
if (err) {
return def.reject(err)
}
return def.resolve(res)
});
return def.promise;
};
Here is the meteorjs code:
async downloadFileFromS3(params) {
try {
const criteria = {
Bucket: params.bucket,
Key: `${params.key}/${params.filename}`
};
const data = await s3.getObject(criteria).promise();
return {
data: data.Body,
contentType: data.ContentType,
filename: params.filename
};
} catch (ex) {
throw new Meteor.Error('500', ex.message);
}
}
Here is what I'm doing in the client side:
function _download (data, filename) {
const blob = new Blob([data.data], {type: data.contentType});
const url = window.URL.createObjectURL(data);
const el = document.createElement('a');
el.style = 'display: none';
el.href = url;
el.download = filename;
document.body.appendChild(el);
el.click();
window.URL.revokeObjectURL(url);
}