Jump to content
  • 0

Use REST API to download a image file and place it into a IMG tag


VincenzoCocciolo
 Share

Question

I'm trying to download one of the file stored in my Application and then place inline the content to a IMG elementi in my HTML page.

This is the best I did. As a result the "data" contains a binary version of the image but the image in the html page is broken.

Any helps is more than welcomed!

    $.ajax({
        url : 'https://c2acw022.caspio.com/rest/v2/files/3512fabc-6f52-464b-ac9f-8bf0c3078773',
        type : 'GET',
        beforeSend: function (xhr) {
            xhr.setRequestHeader("Authorization", "Bearer " + accessToken);
        },
        success: function (data, textStatus, jqXHR) {
            var base64data=btoa(unescape(encodeURIComponent(data)));
            $("#Logo").attr('src', 'data:image/png;base64,' + base64data);
        },
        error: function (jqXHR, textStatus, errorThrown) {
            // do someghing else
         }        
    });

Link to comment
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...