0

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!

Daz
  • 71
  • 2
  • 5
  • How did you confirm that the image even had metadata to begin with? There should be nothing here that could even begin to modify image metadata. (The `MetadataDirective` is about *object* metadata, which is an unrelated thing altogether). – Michael - sqlbot Jun 03 '18 at 01:30
  • Thanks Michael - by re-looking to answer your comment I can see it's actually in another module immediately after this code that we are losing the meta-data - not the code above. I'll close this, apologies. – Daz Jun 03 '18 at 02:17

1 Answers1

0

The code above works fine - it is actually in the next module we have an issue.

Daz
  • 71
  • 2
  • 5