How download base64 data as image?
This is not the most optimized solution, But it works.
var a = document.createElement("a"); //Create <a>
a.href = "data:image/png;base64," + ImageBase64; //Image Base64 Goes here
a.download = "Image.png"; //File name Here
a.click(); //Downloaded file
In your case you can try this
var canvas = document.querySelector("canvas");
var signaturePad = new SignaturePad(canvas);
// Returns signature image as data URL (see https://mdn.io/todataurl for the list of possible parameters)
signaturePad.toDataURL("image/jpeg"); // save image as JPEG
source : https://vuejsexamples.com/vue-signature-pad-component/
Javascript: unable to download the base64 decoded image
Here you can get what you are looking for
How to download a base64-encoded image?
- if not please share some codepen link so i can help you out.
Can I download an image if it's in base64 format?
Note: The examples in the snippets will not work live because Stack Overflow sandboxes snippets without allow-downloads
, but they should work on your page.
Depending on your exact use case, you have different options. The easiest one would be using an <a>
tag with the download
attribute instead of a button, like this:
<a download="myImage.gif" href="data:image/gif;base64,R0lGODdhEAAQAMwAAPj7+FmhUYjNfGuxYYDJdYTIeanOpT+DOTuANXi/bGOrWj6CONzv2sPjv2CmV1unU4zPgISg6DJnJ3ImTh8Mtbs00aNP1CZSGy0YqLEn47RgXW8amasW7XWsmmvX2iuXiwAAAAAEAAQAAAFVyAgjmRpnihqGCkpDQPbGkNUOFk6DZqgHCNGg2T4QAQBoIiRSAwBE4VA4FACKgkB5NGReASFZEmxsQ0whPDi9BiACYQAInXhwOUtgCUQoORFCGt/g4QAIQA7">Download GIF</a>
Downloading and converting image to base64 results in corrupted data
There's no responseType
property. You have to use encoding
property, which defaults to utf8
got(imgUrl, {
encoding: null
})
.then(response => response.body.toString('base64'))
.then(console.log)
Or directly: encoding: 'base64'
got(imgUrl, {
encoding: 'base64'
})
.then(response => response.body)
.then(console.log)
Otherwise you're trying to convert back from an utf8
encoded image, which is why it's broken. You can't convert an image to utf8
and then convert it back.
Related Topics
Filter Json Object Array on Multiple Values or Arguments JavaScript
How to Add Active Class/State for Li Element in Reactjs
Detect If User Is Using Webview for Android/Ios or a Regular Browser
How to Clear the Focus in JavaScript
Force Download an Image from Src Using JavaScript
Getting Null Value in List When Passing by Ajax Call to MVC Controller
How to Merge Two Json Object Values by Id With Plain JavaScript (Es6)
Angularjs:Ng-Model Binding Not Updating When Changed With Jquery
How to Add or Update a Query String Parameter
How to Get the Value by a Key from a Super Nested Json
Getting Name of Parent Object from Value of Object
How to Check Whether Session Is Null or Not in JavaScript
Bootstrap Slides Lagging While Using Multi Item Carousel Using Angular 6
Removing Number from Notification Icon
Method for Splitting String into Separate Cells in Sheets/App Script
How to Remove Errors Warnings from Console