gpt4 book ai didi

javascript - Cloudinary - 直接调用 API 上传,丢失文件

转载 作者:行者123 更新时间:2023-11-28 06:24:59 25 4
gpt4 key购买 nike

嗨,我正在尝试使用 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、时间戳等,我需要发送图像,并且需要将其发送到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。谢谢。

最佳答案

我也遇到了同样的问题。您必须以 JSON 形式发送参数。

关于javascript - Cloudinary - 直接调用 API 上传,丢失文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35204161/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com