我想上传/从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.