0





107
1

I have a service that gives the bitmap data in the form of base64 string.

I am using ajax call to get the data from my service into my HTML5 application.

        jQuery.ajax({
            url: MY_SERVICE_URL,
            type: "GET",
            dataType: "json",
            success: ImageCaptured,
            error: AjaxFailed
       });

"ImageCaptured" method is as follows

    var ImgData = "data:image/bmp;base64," + response.serviceResult;
    window.location.href = ImgData;

This opens the image. But, my requirement is to save the image locally.

I also tried using

    var link = document.createElement('a');
    link.href = ImgData;
    link.download = "Image.bmp";
    link.click();

This gives me network error.

Am I missing something? Any ideas on how to do so?

Thanks in advance.

Edit: I need to open the download dialog for saving the image locally. I am able to display the image in the img tag

Question author Sam | Source

0


1

Found a way out. Hope this helps others.

The change was in "ImageCaptured" function.

    var ImgData = "data:image/octet-stream;base64," + response.serviceResult;

    var link = document.createElement('a');
    link.href = ImgData;
    link.download = FileName + ".bmp";
    document.body.appendChild(link);
    link.click();
    document.body.removeChild(link);

This downloads the image forcibly from the browser.

Answer author Sam

Ask about this question here!