[英]How to retrieve the Metadata from nodejs aws s3 getObject callback data?
I am trying to upload/download an audio chunk file to/from S3 using AWS node SDK.我正在尝试使用 AWS 节点 SDK 向/从 S3 上传/下载音频块文件。 I have tried base64 approach and it works fine.
我尝试过 base64 方法,效果很好。 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
我尝试将回调“数据”打印到控制台,并注意到只有以下参数可用 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.任何帮助表示赞赏。
Is your metaInfo
value a string?你的
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.参考sdk api 文档,
Metadata
是一个字符串映射(ala ~ Metadata: {metaInfo: "myMetaInfoString"}
。我已经使用字符串作为metaInfo
的值测试了您的代码,它确实在data.Metadata.metaInfo
下正确返回参考。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.