如何从nodejs AWS S3的getObject回调数据的元数据? [英] How to retrieve the Metadata from nodejs aws s3 getObject callback data?

查看:597
本文介绍了如何从nodejs AWS S3的getObject回调数据的元数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想上传/从S3使用AWS节点SDK下载一个音频块文件/。我已经试过的base64方法,它工作正常。但我不能够获得元数据回来,我已经捆绑为上传PARAMS的一部分。

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.

下面是code片段上传与元信息:

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);            
    }        
}); 

这是片段下载该文件。元数据是不回调数据的一部分。     我试着打印回调数据来安慰,发现只有以下PARAMS可用     上次更改时间,则contentType,CONTENTLENGTH,ETag的,身体,请求ID

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

任何帮助是AP preciated。

Any help is appreciated.

推荐答案

你的元信息值是一个字符串?

引用的 SDK API文档元数据是一个字符串映射(ALA〜元数据:{元信息:myMetaInfoString} 我已经使用字符串测试了code。作为元信息的价值和它在 data.Metadata.metaInfo 引用正确返回。

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.

这篇关于如何从nodejs AWS S3的getObject回调数据的元数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆