简体   繁体   English

使用抓取保留图像元数据

[英]Retain image metadata using fetch

I'm using fetch to download images from a remote server and then upload to an AWS S3 store. 我正在使用访存从远程服务器下载图像,然后将其上传到AWS S3存储。 The download, setting content-type and uploading are working fine but in the process I am losing the image meta-data (eg 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. 我已经进行了广泛的研究,但看不到如何使用访存来获取它,或者看不到它是否在此处或在aws PutObject调用上丢失了。 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! 任何帮助,不胜感激!

上面的代码工作正常-实际上在下一个模块中,我们遇到了问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM