1

This Meteor code needs to push a file collected from the internet to my S3 bucket.
So I am testing it locally before updating the server which is running in a docker container EC2.

edit
The file I am trying to push is located locally in the same folder as the code file. After running the code, I now can see the file in the S3 bucket but its size is 0.

How can I actually upload the file so that a copy is saved in the bucket? thanks

let s3 = new AWS.S3();
let params = {
  Bucket: "my-bucket-name",
  Key: "myfile.pdf",
};
s3.putObject(params, function (err, data) {
  if (err) console.log(err, err.stack); // an error occurred
  else     console.log(data);           // => { ETag: '"d41d8...27e"' }
});
Fred J.
  • 5,759
  • 10
  • 57
  • 106

1 Answers1

0

I think you need to give it a local filename as well. Key is for the name of the destination file, and you need to tell it which file to read and send.

I gather that you are just getting started here, but you need to think about where these files live. In a production environment, the file system is read only, and there is no concept of the current working directory. It is actually difficult to store files locally, so much so that you shouldn't waste time with this approach.

So when a user uploads a file, it has to go straight to AWS. There are plenty of Meteor packages that can do this for you, and there are even services like Filestack that make it so easy it's not funny :)

So perhaps this exercise of uploading a local file is not worth pursuing :)

Mikkel
  • 7,693
  • 3
  • 17
  • 31
  • The Meteor app will download pdf files from the web using http and need to save it to S3. That is the objective, Any suggestion how to go about it? – Fred J. Aug 31 '17 at 08:47
  • Now we discover what you are really after. There is an answer here: https://stackoverflow.com/questions/22186979/download-file-from-url-and-upload-it-to-aws-s3-without-saving-node-js – Mikkel Aug 31 '17 at 09:09