Monday 10 April 2017

Heroku file upload

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.



via Karthik

No comments:

Post a Comment