S3 callback putObject does not return expected objects

I want to get a link to a file (or the file name is also good) after I uploaded my image to S3. I download using the code below and it worked.

s3Bucket.putObject(data, function(err, data){ if (err) { console.log(err); res.send({result:0}); } else { res.send({result:1}); console.log(data) } }); 

But in the callback data, it has only 1 property, sort of. The document clearly states that it has another object, so how do I get the path to the downloaded file?

+5
source share
1 answer

docs does not mean that the object key will be available in the data callback parameter.

You can process the S3 URI of the created object based on the name of the bucket and the params.Key property in the request data.

Here is an example of how to do this from putObject callback

 s3Bucket.putObject(data, function(err, data) { var params = this.request.params; var region = this.request.httpRequest.region; console.log('s3://' + params.Bucket + '/' + params.Key); console.log('https://s3-' + region + '.amazonaws.com/' + params.Bucket + '/' + params.Key) }); 
+3
source

Source: https://habr.com/ru/post/1240305/


All Articles