javascript - Heroku file upload - Stack Overflow

I have a local file download, which gets triggered in the following fashion.panelBody.append('<

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 badges
Add a ment  | 

1 Answer 1

Reset to default 4

Heroku'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

相关推荐

  • javascript - Heroku file upload - Stack Overflow

    I have a local file download, which gets triggered in the following fashion.panelBody.append('<

    8天前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信