Search code examples
xmljsonapiurlimgur

Imgur API upload.json returns XML?


so am having a little trouble with the anonymous imgur API.

If I go to http://api.imgur.com/2/upload.json - this clearly returns JSON.

If I go to http://api.imgur.com/2/upload.json?key=ANONAPIKEY&image=http:/ - this also returns a JSON formatted error.

However, If I actually try and upload a valid image, say :

http://api.imgur.com/2/upload.json?key=ANONAPIKEY&image=http://www.utra.ca/Pictures/Projects/reprap.jpg

this now returns XML.

Could anyone explain this ? Am I doing something wrong ?

Thanks


Solution

  • Encode your URL before sending it over. This should work, for example:

    http://api.imgur.com/2/upload.json?key=ANONAPIKEY&image=http%3A%2F%2Fwww.utra.ca%2FPictures%2FProjects%2Freprap.jpg

    You can encode your URL in Javascript using encodeURIComponent()

    Example:

    var url = "http://api.imgur.com/2/upload.json?key=ANONAPIKEY&image=" + encodeURIComponent("http://www.utra.ca/Pictures/Projects/reprap.jpg")