I’m storing all of my images on S3 and am having difficulty allowing a user to download the images. When I upload an image (with lepozepo:s3) I create a new document in the Photos collection with the url of the image on S3 so that the images can be used as profile images/etc… on the site. I can upload to S3 and remove on S3 just fine, however, I cannot seem to figure out how to get the file data to the client in order to zip with JSZip. Here is what I have so far:
This is a meteor method that I was hoping to call on the client in order to get the files for me to zip.
getPhotos: function (prefix) {
if (Meteor.isServer) {
var fs = Npm.require('fs');
var s3 = new AWS.S3();
var params = {
Bucket: Meteor.settings.awsBucket,
Prefix: prefix
};
s3.listObjects(params, Meteor.bindEnvironment(function(err, data) {
if (err) {
throw new Meteor.Error("S3 List Objects Error", err);
} else {
data.Contents.forEach(function(photo) {
s3.getObject({Bucket: Meteor.settings.awsBucket, Key: photo.Key}, function(err, data) {
if (err) {
console.log(err, err.stack);
} else {
// what do I do with this data?
}
});
});
}
}));
}
}
My thought was that maybe I need to store the data in a temp images collection and then publish it to the client? However, I’m not sure how to store a buffer (I believe s3.getObject returns a buffer in the form of data.Body) in MongoDB. Even if I stored a buffer in MongoDB I don’t even know what I’d do with it on the client side to turn it into an image.
I’m realizing very quick that I don’t know much about how data works in Node haha. Any help would be appreciated.