I'm using fetch to download images from a remote server and then upload to an AWS S3 store. The download, setting content-type and uploading are working fine but in the process I am losing the image meta-data (e.g. the copyright, date taken, camera etc) from the image. I've research extensively but can't see how to get this using fetch or see if its being lost here or on the aws PutObject call. I'm open to using something than fetch to solve the problem if needed.
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()
Any help much appreciated!