NodeRanger
NodeRanger

Reputation: 40

Imgur API not giving a valid response

The following Imgur Upload API isn't working: *https://api.imgur.com/3/upload *. Any idea what else I can use or if they got a new one? I looked at the docs, but couldn't find anything although I might be missing something here: https://apidocs.imgur.com/?version=latest

Upvotes: 1

Views: 394

Answers (1)

Codigo Morsa
Codigo Morsa

Reputation: 840

Here's the code I use to upload images to imgur. The endpoint is different, I don't know if yours work.

const uploadImg = function(file: any) {
    // Begin file upload
    console.log("Uploading file to Imgur..");

    var apiUrl = 'https://api.imgur.com/3/image';
    var apiToken = <your-token>;

    var settings: any = {
      async: false,
      crossDomain: true,
      processData: false,
      contentType: false,
      type: 'POST',
      url: apiUrl,
      mimeType: 'multipart/form-data'
    };

    var formData = new FormData();
    formData.append("image", file);
    formData.append("album", "your-album-name");  // optional
    settings.data = formData;

    return axios(apiUrl, {
    method: 'post',
    data: formData,
    headers: {Authorization: 'Bearer ' + apiToken,
        Accept: 'application/json'}});
    
}

Upvotes: 2

Related Questions