我正在尝试基于此 codepen 示例构建一个简单的 Cloudinary 图像上传:https ://codepen.io/team/Cloudinary/pen/QgpyOK --
我已经将它转换为可以使用,fetch
但即使我已经进入我的 Cloudinary 设置并创建了一个未签名的上传预设,我将其提供给标题,但我仍然收到错误
POST https://api.cloudinary.com/v1_1/myproject/upload 400 (Bad Request)
带有错误消息
Upload preset must be specified when using unsigned upload
我正在使用的代码如下
_callCloudinaryApi(file, method = 'post') {
const config = {
method
}
const cloudName = "myproject" // fictional project name here
const unsignedUploadPreset = "mypreset" // fictional preset name here
const url = `https://api.cloudinary.com/v1_1/${cloudName}/upload`;
const fd = new FormData();
fd.append('upload_preset', unsignedUploadPreset);
fd.append('tags', 'browser_upload'); // Optional - add tag for image admin in Cloudinary
fd.append('file', file);
if (method !== 'get') {
config.headers = {}
config.headers['X-Requested-With'] = 'XMLHttpRequest'
}
return fetch(url, config)
.then(res => res.json())
.then(res => {
console.log(res)
return res;
})
}
谁能帮我确定可能是什么问题?非常感谢!