首页 > 解决方案 > 如何从nodejs中Jimp库中的结果对象发送请求

问题描述

首先我的代码工作正常,但我正在努力改进它,只是我试图从主机请求一个图像文件,然后用 Jimp 调整它的大小,最后将它上传到我的 Cloudinary 帐户。但在将其发送到 Cloudinary 之前,我实际上在我的办公桌上保留了一份副本,然后引用了该名称。所以我需要知道如何使用来自 Jimp 函数的图像结果,然后将其发送到 Cloudinary 而不在我的驱动器上保留副本?

let imgURL =
    "https://s3-eu-central-1.amazonaws.com/salla-cdn/FY1gllCm5QiMxstupKHqCkNOWuUxWn0jYqrBLrFI.jpeg";

const imgArr = imgURL.split("/");
const imageName = imgArr[imgArr.length - 1];

Jimp.read(imgURL)
    .then(image => {
        image.resize(500, 500).write(`./ready/${imageName}`);//RESIZING DONE
        //START UPLOADING 
cloudinary.uploader.upload(
            `./ready/${imageName}`,
            {
                crop: "limit",
                tags: "samples",
                use_filename: true,
                unique_filename: false
            },
            function(result) {
                console.log(result);
            }
        );
    })
    .catch(err => {
        console.log(err);
    });

标签: javascriptnode.jsimage-processingcloudinaryjimp

解决方案


推荐阅读