在javascript中上载文件时,如何以编程方式设置aws s3对象元数据?
我想为每个文件设置内容类型和内容处置标题,这样以后就不必手动更改标题。
当我尝试下面的代码时,我得到“uncaught(in promise)typeerror:无法读取未定义的属性'add'。
如果我取出中间件代码,文件上传成功,但我必须通过s3控制台手动设置元数据。
任何协助都将不胜感激。
var upload = new AWS.S3.ManagedUpload({
params: {
Bucket: projectBucketName,
Key: jobKey,
Body: file
}
//tags: [{ Key: 'Content-Type', Value: 'application/pdf' }, { Key: 'Content-Disposition', Value: 'inline' }]
});
upload.middlewareStack.add(
(next, context) => async (args) => {
args.request.headers["Content-Type"] = "application/pdf";
const result = next(args);
// result.response contains data returned from next middleware.
return result;
},
{
step: "build",
name: "addContentTypeMetadataMiddleware",
tags: ["METADATA", "CONTENTTYPE"],
}
);
upload.middlewareStack.add(
(next, context) => async (args) => {
args.request.headers["Content-Disposition"] = "inline";
const result = next(args);
// result.response contains data returned from next middleware.
return result;
},
{
step: "build",
name: "addContentDispositionMetadataMiddleware",
tags: ["METADATA", "CONTENTDISPOSITION"],
}
);
promise = await upload.promise();
1条答案
按热度按时间brgchamk1#
要在onject上设置元数据,可以使用s3api。下面是一个用java实现的示例。您可以将其移植到用于javascript的aws sdk。