I have a local file download, which gets triggered in the following fashion.
panelBody.append('<button onclick="downloadCsv(\''+skl+'\')">Download csv</button>')
function downloadCsv(data){
var filename=data+'_report.csv'
var form = $('<form>', {action: '/admin/download', method: 'GET'});
form.append($('<input>', {name: 'file_name', value: filename}));
form.submit();
return false;
}
router.get('/download',helper.isSchoolAdmin,feedController.downloadCsv);
downloadCsv:function(req,res){
var fileName = process.cwd()+'/reports/'+ req.query.file_name;
res.download(fileName,function(err){
if(!err)console.log('down')
});
}
The file itself is written to the specified path in the immediate previous request to a different route. Now this works fine on my local..My question is, what would happen once I deploy it onto heroku? would my file upload and download still work, as I've read that heroku uses an ephimeral file system which allows writing only to a tmp directory.
If that's the case, could someone walk me through on how exactly to write to that directory through node...and also, would the file end up getting deleted before I could download it, since the upload and download are part of separate requests? Thanks.
I have a local file download, which gets triggered in the following fashion.
panelBody.append('<button onclick="downloadCsv(\''+skl+'\')">Download csv</button>')
function downloadCsv(data){
var filename=data+'_report.csv'
var form = $('<form>', {action: '/admin/download', method: 'GET'});
form.append($('<input>', {name: 'file_name', value: filename}));
form.submit();
return false;
}
router.get('/download',helper.isSchoolAdmin,feedController.downloadCsv);
downloadCsv:function(req,res){
var fileName = process.cwd()+'/reports/'+ req.query.file_name;
res.download(fileName,function(err){
if(!err)console.log('down')
});
}
The file itself is written to the specified path in the immediate previous request to a different route. Now this works fine on my local..My question is, what would happen once I deploy it onto heroku? would my file upload and download still work, as I've read that heroku uses an ephimeral file system which allows writing only to a tmp directory.
If that's the case, could someone walk me through on how exactly to write to that directory through node...and also, would the file end up getting deleted before I could download it, since the upload and download are part of separate requests? Thanks.
Share Improve this question asked Apr 11, 2017 at 3:08 Karthik Karthik 1143 silver badges11 bronze badges1 Answer
Reset to default 4Heroku's "ephemeral filestystem" is due to the containerisation of the app. When your app is built, an LXC container is sent to the runtimes and executed.
That means any file written on the filesystem will not be persisted accross redeploys, app restarts and multiple dynos. Even in the tmp folder.
You shouldn't store those files on disk, but on a dedicated file storage platform such as Amazon S3 or Google Cloud Storage.
See https://devcenter.heroku./articles/s3-upload-node
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744258552a4565514.html
评论列表(0条)