I am using Nodejs to try to push an image onto an S3 instance using aws-sdk. It currently reads from a file on the client and then saves it on the server (I use the meteor structure.) I would like to push it to the S3 server instead of saving the meteorites to the server. When I tried to transfer it, the images seem to get about 30% when they are on S3. If I try to download them from S3, the image will no longer be visible, so it looks like it changed the encoding or something like that.
Here is the code to download the file on the client side:
saveFile = function( blob, name, path, type, callback ) { var fileReader = new FileReader(); var method; var encoding = 'binary'; var type = type || 'binary'; switch( type ) { case 'text': method = 'readAsText'; encoding = 'utf8'; break; case 'binary': method = 'readAsBinaryString'; encoding = 'binary'; break; default: method = 'readAsBinaryString'; encoding = 'binary'; break; }
On the server side:
saveFile: function( file, name, path, encoding ) { s3.createBucket({Bucket: bucketName}, function() { var params = {Bucket: bucketName, Key: keyName, ContentType: 'binary', ContentEncoding: 'utf8', Body: file}; s3.putObject(params, function(err, data) { if (err) console.log(err) else console.log("Successfully uploaded data to " + bucketName + "/" + keyName); }); });
source share