Getting 405 Method Not Allowed error while uploading GIF to Giphy API

I’m working on a project where I need to upload animated GIFs to Giphy using their API. However, every time I try to make the request, I get a 405 Method Not Allowed error and I can’t figure out what’s causing it.

Here’s my current code:

const uploadGif = async (gifData, token) => {
  try {
    const response = await fetch(`https://upload.giphy.com/v1/gifs?api_key=${token}&file=${gifData}`, {
      method: 'POST',
      body: JSON.stringify(gifData),
      headers: {
        'Content-Type': 'image/gif'
      }
    });
    
    if (response.ok) {
      const result = await response.json();
      return result;
    } else {
      console.log('Upload failed');
    }
  } catch (err) {
    console.log('Request error: ' + err);
  }
};

I’ve checked the Giphy documentation but I’m still stuck. Has anyone encountered this issue before? Any help would be appreciated.

Your main problem is how you’re handling the file data. You’re passing gifData as a URL parameter AND stringifying it in the body - that conflicts with your content type header. For Giphy uploads, use FormData to handle the binary file properly. Create a FormData object, append your gif file, and drop the Content-Type header so the browser sets it automatically with the boundary. Also double-check you’re hitting the right endpoint - 405 errors often mean wrong URL path. I had the same issue until I switched to FormData and it fixed the method not allowed error right away.