Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict';
- const util = require('util');
- const fs = require('fs');
- const write = util.promisify(fs.writeFile);
- module.exports = ({ image, identifier, directory }) => {
- try {
- const extension = image.split(';')[0].match(/jpeg|png|gif/)[0];
- const data = image.replace(/^data:image\/\w+;base64,/, '');
- const encoding = 'base64';
- const file = `${identifier}.${extension}`;
- const path = path.join(directory, file);
- await writeFile(path, data, encoding);
- return path;
- } catch (error){
- console.error(error);
- return null;
- }
- }
Add Comment
Please, Sign In to add comment