Here is the ready working code, but how to specify the file from the computer and not from the server var imgUrl = "http://i.imgur.com/l5OqYoZ.jpg"; ?

 var clientId = "6b72b846602****"; var imgUrl = "http://i.imgur.com/l5OqYoZ.jpg"; $.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); } }); function showMe(data) { $("body").append(JSON.stringify(data)); if(data.success == true) { $("body").append("<img src='"+data.data.link+"'/>"); } } 

    1 answer 1

    Just replace the line with a link to the file from input[type='file'] .
    And also specify the type parameter - file .

    The image parameter can be a binary file, base64 encoded data, or an image link.

    enter image description here

    Read more in the documentation .

    • Here is a picture in Base64, but it does not work. If you var imgUrl = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUAQMAAAC3R49OAAAAA1BMVEV+Xl5R/nSpAAAAC0lEQVR4XmOgMgAAAFAAAWTxy78AAAAASUVORK5CYII="; - gilo1212
    • I also indicated this: data: {image: imgUrl, type: 'file'}, - gilo1212
    • @ gilo1212, for base64 you need to set the type as base64 , see the document. - user207618
    • Doesn't want to work anyway - data: {image: imgUrl, type: 'base64'}, - gilo1212
    • Maybe you need to transfer the file name somehow? - gilo1212