ReadFile in Base64 Nodejs

前端 未结 3 459
既然无缘
既然无缘 2020-12-13 03:37

I\'m trying to read an image from client side encoded in base64. How to read with nodejs?

My code:

// add to buffer base64 image
var encondedImage =          


        
3条回答
  •  清歌不尽
    2020-12-13 04:20

    Latest and greatest way to do this:

    Node supports file and buffer operations with the base64 encoding:

    const fs = require('fs');
    const contents = fs.readFileSync('/path/to/file.jpg', {encoding: 'base64'});
    

    Or using the new promises API:

    const fs = require('fs').promises;
    const contents = await fs.readFile('/path/to/file.jpg', {encoding: 'base64'});
    

提交回复
热议问题