Question

I have been looking through various posts on Stack which eventually lead me to this thread which focuses on PHP uploads.

I am familiar with accessing APIs but generally over PHP. I recognize that some if not most API calls will require a backend system. But I am curious if it is possible to create an API call to upload onto Imgur strictly using jQuery? No other backend like Python or RoR or PHP or anything?

My current client ID is used for anonymous upload so there is no OAuth or any other connection. I can get this working in PHP but I would love to make the application Ajax-based without refreshing the page. Any steps in the right direction would be more than appreciated.

Was it helpful?

Solution

v2 works for me

    var imageData = "base64 encoded data here";

    $.post("http://api.imgur.com/2/upload", {key:"your_api_key", type:"file", image:imageData}, function(page)
    {
        console.log(page);
    });

I just tested this and it uploaded my image

OTHER TIPS

function uploadImage(){
 $.ajax({
  url: 'https://api.imgur.com/3/image',
  headers: {
  'Authorization': 'Client-ID xxxxxxxxx'
  },
  type: 'POST',
  data: {
    'image': 'http://static.dnaindia.com/sites/default/files/styles/half/public/2015/11/30/399839-deepika-padukone.jpg?itok=Ba0msbiw'
  },
 success: function(data) { console.log(data.data.link); }
  });
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top