【问题标题】:Why is my Giphy API's POST request returning status 400?为什么我的 Giphy API 的 POST 请求返回状态 400?
【发布时间】:2020-07-23 13:09:43
【问题描述】:

我正在尝试通过他们的 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;
    }
)

upload.append()里面的gif变量的值是recorder.getBlob()(我用的是RecorderRTC API),我也试过用upload.file甚至upload.get("file")作为源,也用@987654327 @ 并在获取请求中将file= 更改为source_image_url=,甚至尝试在不使用FormData() 的情况下发送gif 变量,但没有任何效果。

你有线索吗?

【问题讨论】:

    标签: javascript post http-status-code-400 giphy-api


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-19
      • 2015-12-08
      • 1970-01-01
      • 2021-11-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多