On Monday, February 6, 2017 at 9:29:21 PM UTC+1, אלה וייס wrote:
>
> .
> 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
>
>
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?
--
Job board: http://jobs.nodejs.org/
New group rules:
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/nodejs/64c351d8-bc19-4491-9902-2a8d3a65e32f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.