We’re storing file uploads on S3 with edgee:slingshot
, meaning the files are uploaded directly from client -> S3.
However for download, we pass through our server, meaning S3 -> server -> client.
Right now, when the user clicks on download, we just use a simple meteor method:
Meteor.methods({
downloadFile: (key) => s3.getObject(key), // Simplified for demonstration purposes
})
This properly returns the file on the client, which is then downloaded with the file-saver
library to his computer.
The problem with this is, when users are downloading large files, this completely crashes the app with this error:
2018-10-16 15:21:05 [APP/PROC/WEB/0] ERR Killed
2018-10-16 15:21:05 [APP/PROC/WEB/0] ERR npm ERR! code ELIFECYCLE
2018-10-16 15:21:05 [APP/PROC/WEB/0] ERR npm ERR! errno 137
2018-10-16 15:21:05 [APP/PROC/WEB/0] ERR npm ERR! my-meteor-app@ start: `node launcher.js`
2018-10-16 15:21:05 [APP/PROC/WEB/0] ERR npm ERR! Exit status 137
2018-10-16 15:21:05 [APP/PROC/WEB/0] ERR npm ERR!
2018-10-16 15:21:05 [APP/PROC/WEB/0] ERR npm ERR! Failed at the my-meteor-app@ start script.
2018-10-16 15:21:05 [APP/PROC/WEB/0] ERR npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2018-10-16 15:21:05 [APP/PROC/WEB/0] ERR npm ERR! A complete log of this run can be found in:
2018-10-16 15:21:05 [APP/PROC/WEB/0] ERR npm ERR! /home/vcap/app/.npm/_logs/2018-10-16T13_21_05_399Z-debug.log
2018-10-16 15:21:05 [APP/PROC/WEB/0] OUT Exit status 137 (out of memory)
I presume it is caused by what is described in this stack overflow issue: https://stackoverflow.com/questions/20875314/download-large-file-from-node-http-server-the-server-out-of-memory
So has someone already written meteor methods that return a node stream? or something similar to stream the file to the client ?