为什么我的Giphy API的POST请求返回状态400?

问题描述 投票:0回答:1

我正在尝试通过网络摄像头Feed通过其API将gif上传到Giphy,并且它返回状态400-“请提供文件上传或'source_image_url'”。我的功能是这样做的:

upload = new FormData();
upload.append("file", gif, "usergif.gif");
console.log(upload.get("file"));

fetch("https://upload.giphy.com/v1/gifs?file=" upload + "&api_key=" + apiKey, { method: "POST" })
    .then(response => {
        console.log(response.status);
        return response.json;
    }
)

gif内的upload.append()变量的值为recorder.getBlob()(我正在使用RecorderRTC API),我也试图将其用作源upload.file甚至是upload.get("file"),也使用了URL.createObjectUrl(gif)并在获取请求中将file=更改为source_image_url=,甚至尝试不使用gif来发送FormData()变量,但无济于事。

你有线索吗?

javascript post http-status-code-400 giphy-api
1个回答
0
投票

对于那些有兴趣的人,解决方案是,当使用POST方法时,必须使用要上传的文件指定body标头

© www.soinside.com 2019 - 2024. All rights reserved.