How to get metadata from datajs aws s3 getObject callback data?

I am trying to upload / download an audio file to / from S3 using the AWS node SDK. I tried the base64 approach and it works great. But I can’t get back the metadata that I put in the download options part.

Below is a snippet of code to download along with the meta information:

var myMetaInfo = "AdditionalInfo", dataToUpload = {Bucket: bucketName, Key:storageFolderFullPath , Body: myAudioFile.toString('base64'), Metadata: {metaInfo: myMetaInfo}}; s3.client.putObject(dataToUpload, function(err, data) { if (!err) { console.log("Successfully uploaded the file to ::" + dataToUpload.Bucket); } else { console.log(" **** ERROR while uploading ::"+err); } }); 

And this is a snippet for downloading a file. Metadata is not part of the callback data. I tried to print the callback data on the console and noticed that only the following parameters LastModified, ContentType, ContentLength, ETag, Body, RequestId are available

 var dataToDownload = {Bucket: bucketName, Key: storageFolderFullPath}, originalFile, myMetaInfo; s3.client.getObject(dataToDownload, function(err, data) { if (!err) { originalFile = new Buffer(data.Body, 'base64'); myMetaInfo = data.Metadata.metaInfo; console.log(" Meta info:: " + myMetaInfo); fs.writeFile(fileStoragePath, originalFile, function(err) { if (!err) { console.log(" File written!! "); } else { console.log(" Error while writing the file !!" + err); } }); } else { console.log(" **** ERROR while downloading ::"+err); } }); 

Any pointers to what is wrong with my implementation? I followed the documentation mentioned here

Any help is appreciated.

+4
source share
1 answer

Is your metaInfo a string value?

The link to sdk api docs , Metadata is a string map (ala ~ Metadata: {metaInfo: "myMetaInfoString"} . I checked your code using string as the value for metaInfo , and it correctly returns the data.Metadata.metaInfo link.

0
source

All Articles