Skip to content
This repository has been archived by the owner on Feb 12, 2021. It is now read-only.

Stream file directly to client #53

Closed
deathg0d opened this issue Oct 11, 2014 · 11 comments
Closed

Stream file directly to client #53

deathg0d opened this issue Oct 11, 2014 · 11 comments

Comments

@deathg0d
Copy link

Is there a way to stream file directly to client without saving it in the server? I have also posted a question on this issue here: http://stackoverflow.com/questions/26312294/streaming-files-directly-to-client-from-amazon-s3-node-js

I have pasted the question below:


I am using sails.js and am trying to stream files from the Amazon s3 server directly to the client.

To connect to S3, I use the s3 Module : https://www.npmjs.org/package/s3 This module provides capabilities like client.downloadFile(params) and client.downloadBuffer(s3Params).

My current code looks like the following:

var view = client.downloadBuffer(params);
view.on('error', function(err) {
    cb({success: 0, message: 'Could not open file.'}, null);
});
view.on('end', function(buffer) {
    cb(null, buffer);
});

I catch this buffer in a controller using:

User.showImage( params , function (err, buffer){
    // this is where I can get the buffer
});

Is it possible to stream this data as an image file (using buffer.pipe(res) doesn't work of course). But is there something similar to completely avoid saving file to server disk first?

The other option client.downloadFile(params) requires a local path (i.e. a server path in our case)

@andrewrk
Copy link
Owner

I suggest using the aws SDK directly. I don't think there would be a benefit to adding downloadStream to this module. The aws SDK already supports downloading a stream.

@deathg0d
Copy link
Author

Hi, @andrewrk, I used your client.downloadBuffer and plugged the output buffer directly into my sails app like this return res.end(buffer);. It does seem to work. However, I am struggling with maintaining cache on images.

The aws SDK already supports downloading a stream. >> yes but don't want to use too many modules to do similar things. My code is already a big pile of mess :|

@andrewrk
Copy link
Owner

I advise against using downloadBuffer for this use case. You should use a stream. Would it help if this module exposed the aws-sdk dependency?

@deathg0d
Copy link
Author

@andrewrk I would assume it would be quite handy to have the feature to directly stream files to the client.

@andrewrk
Copy link
Owner

Alright. I'll add downloadStream even though it's really a superfluous wrapper around aws sdk. I can see how it would be nice to only have 1 set of documentation to read.

@andrewrk andrewrk reopened this Oct 11, 2014
@deathg0d
Copy link
Author

Thanks that would be great. I really appreciate your work on this module. Thanks.

@deathg0d
Copy link
Author

@andrewrk Any updates on this addition?

@andrewrk
Copy link
Owner

Not yet.

@deathg0d
Copy link
Author

Thanks for adding this. Is this update going to npm any time soon?

@andrewrk
Copy link
Owner

Yeah. There are a few other issues I want to solve with this release though. I observed some weird behavior in master branch and I want to figure out what it was before releasing.

@andrewrk
Copy link
Owner

Sorry for the delay.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants