【问题标题】:Multer Cloudinary NodeJsMulter Cloudinary NodeJs
【发布时间】:2018-05-24 12:43:25
【问题描述】:

我正在尝试通过邮递员使用form-data 将图像上传到cloudinary 我也在使用名为 multer-storage-cloudinary 的 npm 包。但是,我遇到了麻烦。这是我的代码:

cloudinary.config({
    cloud_name: 'ax850',
    api_key: config.CLOUDINARY_API_KEY,
    api_secret:config.CLOUDINARY_API_SECRET_KEY
});

let storage = cloudinaryStorage({
    cloudinary: cloudinary,
    folder: '/Memory',
    allowedFormats: ['jpg', 'png'],
    filename: function (req, file, cb) {
        cb(undefined, 'testing');
    }
});

let parser = multer({ storage: storage });
app.post('/upload', parser.array('images', 10), function (req, res) {
    console.log(req.files);
});

没有错误,它只是在崩溃前几乎冻结了。我的云端有一个/Memory 文件夹。 有什么想法吗?

【问题讨论】:

  • 您需要 multer 和 cloudinary 包,并且在定义文件夹时尝试不使用 /,因此它将是 `folder: "Memory",

标签: node.js cloudinary


【解决方案1】:

您可以尝试执行以下操作:

函数处理文件(e){

    var f = document.getElementById('f');       
    var file = f.files[0];
    var formdata = new FormData();

    formdata.append('file', file);
    formdata.append('cloud_name', '<cloud_name>');
    formdata.append('resource_type', 'image');

    var xhr = new XMLHttpRequest();
    xhr.open('POST', "https://api.cloudinary.com/v1_1/<cloud_name>/image/upload",true);


    xhr.onload = function () {
    // do something to response
        console.log(this.responseText);
    };

    xhr.send(formdata);     
}

【讨论】:

    猜你喜欢
    • 2021-09-02
    • 2021-04-26
    • 2021-12-12
    • 2020-12-18
    • 2021-04-05
    • 2016-02-02
    • 2015-06-12
    • 2017-05-25
    • 2019-01-06
    相关资源
    最近更新 更多