Jump to content
  • 0

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


VincenzoCocciolo

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

1 answer to this question

Recommended Posts

  • 0
On 10/11/2021 at 1:47 PM, VincenzoCocciolo said:

    $.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
         }        
    });

Were you ever able to make this work?

Link to comment
Share on other sites

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...
×
×
  • Create New...