Showing image from nodejs - aws s3

Hi,

In my nodejs server I have a function that gets an image from the s3 server and serves it:

My node function is:

function getPhoto(file, res) {
	var data = "";
	knox.get(file).on('response', function(s3res){

	    s3res.setEncoding('binary');
	    s3res.on('data', function(chunk){
	      data += chunk;
	    });
	    s3res.on('end', function() {
		    res.contentType(s3res.headers['content-type']);
		    res.write(data, encoding='binary')
		    res.end();
	    });
	  }).end();
}

so then i can show the picture on fuse using:

<Image>
	<HttpImageSource Url="http://server/myRequest"/>
</Image>

my question is: how do i show the picture in fuse if I pipe the picture from s3 instead of writing the result?

my function (that works when requesting the file from a browser but not when requesting it from fuse):

function getPhoto(file, res) {
	knox.getFile(file, function(err, imageStream) {
        imageStream.pipe(res);
    });
}

Can’t S3 give you an URI that you can pass to Fuse?

yes it does BUT it expires so it does solve half of my problem.

It’s in my newsfeeds page: I store the results in a .json file so when the user is back i load the last results (till i get the new ones) so the URI would work for a new request but not when i load the previous results when the user launches the app after 1 hour (for example)

Then you would have to write a custom ImageSource in Uno that display the raw data (I show a small example for how to show base64 images here). Could you just extend the expiration time on the image URL’s in S3 instead maybe?

Hi!

do you think that would be solved? (not a high priority but it will be good to know)

the obvious problem is that i need 1 more request (so it takes a bit longer) to show the image:

1.- request the image URL

2.- get the image from that URL

The solution you gave me won’t be “as easy” to implement as the url shown is not always coming from s3 (i would have to check where the image is coming from and then show it in your custom class or the regular HttpImageSource)

zaulin@yahoo.com wrote:
do you think that would be solved? (not a high priority but it will be good to know)

I do not understand exactly what you want us to change in our API?

zaulin@yahoo.com wrote:
the obvious problem is that i need 1 more request (so it takes a bit longer) to show the image:

This is not obvious to me since I don’t have a lot of experience with S3. Nor do I understand your use case. Could you try to explain a bit more about how this works and why you are doing it this way.

zaulin@yahoo.com wrote:
The solution you gave me won’t be “as easy” to implement as the url shown is not always coming from s3 (i would have to check where the image is coming from and then show it in your custom class or the regular HttpImageSource)

My solution is only based on vague assumptions on what you are doing. If you elaborate more I might be able to come up with something else. I can’t see a reason for why you just cant’t return an array of all your URI’s to fuse?

Maybe I’m missing the point (not sure what the difference between piping and writing the result is) but I don’t see the principal difference between this and any other redirect other than your implementation maybe being a bit naive and our implementation maybe being a bit strict?

When you say it “doesn’t work” what is the error message you are getting? If you need a better error message for the Image you can use <Image Url="..." Error="{errorHandler}"/> where errorHandler is

	console.log(error.reason)
}```

Hi,

solved:

the problem was that the header was not set in the function that used pipe:

exports.getPhoto = function(file, res) {
	knox.getFile(file, function(err, imageStream) {
		res.setHeader('Content-type', 'image/' + file.split('.').pop(););
        imageStream.pipe(res);
    });
}

my confusion came from the fact that the browser was showing the image propertly (without the header) so that’s why i thought there was a problem with fuse.

Sorry!