node.js如何将当前目录下图片读取成base64

      // 引入模块
      const fs = require('fs');
      // 该路径可以查看上一篇文章-如何将远程图片读取到当下目录
      const filePath1 = "/tmp/"+ time+".png";
      // 通过request发起post请求上传文件到服务器
      // 获取图片的base64 
      let imageData = fs.readFileSync(filePath1); // 例:fileUrl="D:\\test\\test.bmp"
      let imageBase64 = imageData.toString("base64");
      

你可能感兴趣的:(node.js如何将当前目录下图片读取成base64)