5

I am trying to upload/download an audio chunk file to/from S3 using AWS node SDK. I have tried base64 approach and it works fine. But I am not able to get the Metadata back which I have bundled as part of upload params.

Below is the code snippet for upload along with meta info:

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 the snippet for downloading the file. Metadata is not part of the callback data. I tried printing the callback 'data' to console and noticed that only the following params are available LastModified, ContentType, ContentLength, ETag, Body, RequestId

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 on what is wrong with my implementation? I have followed the documentation mentioned here

Any help is appreciated.

1 Answer 1

1

Is your metaInfo value a string?

Referencing the sdk api docs, Metadata is a string map (ala ~ Metadata: {metaInfo: "myMetaInfoString"}. I've tested your code using a string as the value for metaInfo and it does return correctly under the data.Metadata.metaInfo reference.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.