【发布时间】:2016-05-14 06:00:29
【问题描述】:
您好,我正在尝试使用 React JS 中的 Cloudinary,因此我使用的是从浏览器直接调用 API。我有服务器返回我 api_key 等...
我正在使用 readAsDataURL() 将我的文件更改为 base64
let file = e.target.files[0];
let self = this;
let typeString = this.tellType(file);
let reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = function(){
self.sendMedia(typeString, this.result)
}
然后我从客户端 nodejs 服务器获取 api_key、timestamp 等,我需要发送图像并将其发送到 cloudinary。
let request = new XMLHttpRequest();
let params = {
api_key: result.upload_info.api_key,
timestamp: result.upload_info.timestamp,
signature: result.upload_info.signature,
public_id: result.upload_info.public_id,
file: file
};
console.log('params',params);
request.open('POST', `https://api.cloudinary.com/v1_1/${cloud_name}/image/upload`, true);
request.onreadystatechange = function() {
console.log('its back', request)
};
request.send(params);
然后我收到 403(错误请求)
responseText: "{"error":{"message":"Missing required parameter - file"}}"
我第一次想到我的文件格式错误,但是cloudniary允许base64。 谢谢。
【问题讨论】:
-
Cloudinary 完全支持使用 base64 上传。虽然看起来“文件”属性没有被正确传递。
file: file里面是什么?您是否将this.result作为“文件”的值发送?
标签: javascript base64 cloudinary