Store images in node.js express web site

46 views
Skip to first unread message

אלה וייס

unread,
Feb 6, 2017, 3:29:21 PM2/6/17
to nodejs
Hello,

.
I put my images in a directory  inside node.js public folder

 :in order to be able to read all images from folder using $.ajax

(((app.use('/albums',serveIndex(path.join(__dirname,'public/AlbumImages

(((app.use('/albums',express.static(path.join(__dirname,'public/AlbumImages

My question is:

 ?In case I have images on another server ,How can I do the same

thanks.

Zlatko

unread,
Feb 7, 2017, 10:27:36 AM2/7/17
to nodejs
Technically, yes. But the question is why, of course.There are multiple ways to have this done, depending on your use case:

- If those are simple, static assets, you might want to skip node completely - just tell your nginx, load balancer or whatever to route requests for images to another server.            
- Alternatively, maybe you wanna process access rights before you serve those - e.g. user can only have his own images. You might have image URLs in the database, and Express only has an endpoint that serves you the links to those images. Then the client fetches those from the locations given.
- Or maybe you actually do want to get images from another server. Again, we must branch off.
- you access them some other way? E.g. via samba or some other networked file system? Then as long as the remote file system is mounted locally, use the same or similar approach to what you have. Maybe just stream the images instead of serving directly, to avoid buffering whole images in your express app.
- Are the pics available via HTTP? Then something simple like app.get('/albums',  (req, res) => require('request')('http://remote-url/' + req.url).pipe(res));
- some other means of access? Well, simple - take your request, then you yourself request the remote file, then pass on the response or response stream to your client.

Maybe you can share more details on what exactly is your use case?


 
 
Reply all
Reply to author
Forward
0 new messages