我正在尝试通过网络摄像头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()
变量,但无济于事。
你有线索吗?
对于那些有兴趣的人,解决方案是,当使用POST方法时,必须使用要上传的文件指定body
标头