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.
source share