1

I create a .xls file in assets/xls directory :

fs.writeFileSync('./assets/xls/data.xls', xls, 'binary');

And I want to download this file :

To get the file url :

var downloadLink = req.headers.host+'/xls/data.xls';

I do not understant why I have a 404 error on this url :
localhost:1337/xls/data.xls

Travis Webb
  • 14,688
  • 7
  • 55
  • 109
damien marchand
  • 864
  • 1
  • 13
  • 30

1 Answers1

2

This isn't the recommended practice for storing generated or user-uploaded files. The assets folder is only intended for your site's front-end assets.

If you want to provide download links in your app, you're encouraged to save them in a separate location and add a controller action that streams the requested file to the client. This allows you to add policies to protect those files, and avoids issues source control and with Grunt. See How do I authenticate access to assets folder in sails.js for an example of such a controller action.

Community
  • 1
  • 1
sgress454
  • 24,870
  • 4
  • 74
  • 92