Why is my Giphy API's POST request returning status 400?

545 Views Asked by At

I'm trying to upload a gif from the webcam feed to Giphy through their API and it returns status 400 - "Please supply a file upload or a 'source_image_url'". My function does this:

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;
    }
)

The gif variable inside upload.append() has a value of recorder.getBlob() (I'm using the RecorderRTC API), I also tried to use as a source upload.file and even upload.get("file"), also used URL.createObjectUrl(gif) and changed file= for source_image_url= in the fetch request, even tried to send the gif variable without the use of FormData() but nothing worked.

Do you have a clue?

1

There are 1 best solutions below

0
On

For those interested, the solution was that when using the POST method, you gotta specify a body header with the file to be uploaded