我正在尝试使用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);
});
没有错误,它几乎在崩溃前冻结。我的cloudinary中有一个/Memory
文件夹。
有什么想法吗?
答案 0 :(得分:0)
您可以尝试实施以下内容:
function processFile(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);
}