node.js - Accessing a s3 bucket from Node -


i have basic node application user logs in , able view links files stored in directory within app. file structure looks this.

├── app

├── public

├── node_modules

├── secure (files stored here)

├── .ebextensions

├── .elasticbeanstalk

├── package.json

└── app.js

the secure/ directory files stored (approx 350mb).

here example of link file in directory href="/secure/folder/document.pdf"

i've moved whole secure/ folder s3 bucket keep file size of application down.

would have suggestions on how go allowing node application access bucket?

i have middleware on routes secure/ check if user authenticated, link can't distributed users aren't logged in.

here attempt @ it!

var aws = require('aws-sdk'),  s3 = new aws.s3({    region : 'example_region'   });  app.get('/secure/:endpoint',function(req,res){   var     stream = s3.getobject({       bucket: 'examplebucket',       key: 'secure/' + req.params.endpoint     }).createreadstream();   stream.pipe(res); }); 

i'm able access link similar href="/secure/userguide.pdf", when start going more 1 level deep file system e.g href="/secure/foldar1/userguide.pdf" throws 404 error.

making comment answer since led solution.

you should rewrite routing this:

app.get('/secure/*', function(req, res){...}  

hence every request start /secure/ attach router. , can extract path access req.originalurl .


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -