Convert and save base64 image data to file.
$ npm i node-base64-to-image --save
const SaveBase64 = require('node-base64-to-image');
// or
import { SaveBase64 } from 'node-base64-to-image';
app.use((req, res, next) => {
const base64Data = `data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJUAAABOCAYAAAApW1S...`;
const imageNameWithPath = `${__dirname}/public/images/sample-image.jpeg`;
SaveBase64(base64Data, imageNameWithPath, 'jpeg')
.then(success => {
res.send(success);
}, err => {
throw err;
});
});
Key | Description |
---|---|
base64DataToSave | Base64 image data to save into file. |
imagePathToSaveWithName | Absolute path where image need to save with the name of the image to save. |
imageExtension | Extension of the Base64 image data. |
Licensed under MIT. See LICENSE for more information.
Report a bug in ISSUES.