我正在使用fetch从远程服务器下载图像,然后上传到 AWS S3 商店。下载、设置内容类型和上传工作正常,但在此过程中我丢失了图像中的图像元数据(例如版权、拍摄日期、相机等)。我进行了广泛的研究,但看不到如何使用 fetch 来获取它,或者看它是否在此处丢失或在 aws PutObject 调用中丢失。如果需要,我愿意使用 fetch 以外的东西来解决问题。
const fetch = require('node-fetch');
let ext = imageURL.split("?")[0].split(".").pop();
// console.log(ext);
let contType = "";
switch (ext.toLowerCase()) {
case "jpg":
contType = "image/jpeg";
break;
case "jpeg":
contType = "image/jpeg";
break;
case "png":
contType = "image/png";
break;
case "gif":
contType = "image/gif";
break;
case "svg":
contType = "image/svg+xml";
break
default:
contType = "application/octet-stream";
}
console.log(`Using content type ${contType} for ${ext}`);
let response = await fetch(imageURL);
if (response.ok) {
let buffer = await response.buffer()
await s3.putObject({
Bucket: config.bucket,
Key: "images/" + filename + "." + ext,
Body: buffer,
ContentType: contType,
//MetadataDirective: "COPY"
}).promise()
非常感谢任何帮助!