Imgur API Version 3 JavaScript upload example
Asked Answered
E

2

16

All the examples I find online are of earlier versions of the Imgur API or non JS code all of which uses an API key which doesn't exist in the newer API. Instead you get a client_id and secret. Anyone have example code that shows how an image can be uploaded to Imgur through JavaScript (or jQuery) using version 3 of their API?

Elvaelvah answered 6/8, 2013 at 19:8 Comment(0)
A
21
$.ajax({ 
    url: 'https://api.imgur.com/3/image',
    headers: {
        'Authorization': 'Client-ID YOUR_CLIENT_ID'
    },
    type: 'POST',
    data: {
        'image': 'helloworld.jpg'
    },
    success: function() { console.log('cool'); }
});
Aleedis answered 6/8, 2013 at 21:34 Comment(7)
I get this message: " POST api.imgur.com/3/image 403 (Permission Denied) "Dactylogram
@Aleedis awesome thanks so much. Been confused about this for weeks.Elvaelvah
@acudars did you change this part: "YOUR_CLIENT_ID" with the client id you recieved after registering your app here api.imgur.com/oauth2/addclient ?Elvaelvah
why the response I get is 1203 image over capacity? even after I used a very small image?Pacify
@Aleedis Why i have error? $.ajax({ url: 'https://api.imgur.com/3/image', headers: { 'Authorization': '6b72b886602****' }, type: 'POST', data: { 'image': '111.PNG' }, success: function() { console.log('cool'); } });Selfsatisfied
I sill get permission denied after putting my own client id as well.Valparaiso
Im getting error 429, SO link: #66874183Tristan
C
0

Building on @vin's example here is one:

$(document).ready(function() {
    $.ajax({
        url: 'https://api.imgur.com/3/image',
        headers: {
            'Authorization': 'Client-ID a1b2c3d4e5'
        },
        type: 'POST',
        data: {
            'image': image
        },
        success: function(data, status) {
            console.log("Data: " + data.data.link + "\nStatus: " status);
            console.log(data.data.link)
        }
    });
});

This lets you save the url to the file.

Currant answered 28/1, 2022 at 17:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.