Search code examples
javascriptshared-hostingimgur

How to upload image to imgur album?


I would like to upload image to own album by using javascript.

This code can upload image to imgur, but I dont know how to upload it to my album.

http://jsfiddle.net/FGxGg/57/

$.ajax({
url: "https://api.imgur.com/3/upload",
type: "POST",
datatype: "json",
data: {image: imgUrl},
success: showMe,
error: showMe,
beforeSend: function (xhr) {
    xhr.setRequestHeader("Authorization", "Client-ID " + clientId);
}});

Or any suggestion for image hosting to own album?


Solution

  • Imgur has detailed API documentation on all their endpoints, including Image Upload.

    According to the documentation, you can supply an album parameter with the id of the album you want to upload to. So, change your data to include it:

    var clientId = ""; // Your client Id
    var imgUrl = "http://i.imgur.com/l5OqYoZ.jpg";
    var albumId = 'ABC123'; // Your owned album id
    
    $.ajax({
      url: "https://api.imgur.com/3/upload",
      type: "POST",
      datatype: "json",
      data: {image: imgUrl, album: albumId},
      success: showMe,
      error: showMe,
      beforeSend: function (xhr) {
        xhr.setRequestHeader("Authorization", "Client-ID " + clientId);
    }});