base图片存为images

base图片存为images

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
const fs = require('fs');

// 要写入的 Base64 编码的图片数据
const base64Data = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAD4AAABFCAYAAAASJFVGAAAAAXNSR0IArs4c6QAAAARzQklUCAgICHwIZIgAABKySURBVHic5VxbbBzXef7OmfvM3s2lxEtJmTZFk7ZlRwkiJIhza2skTwFatAWaFmiAoCgCBEX61JcUQS9PRYE+tE3RIgGMtHGKAA2QNC2gBIVqx0qgRI5jWrRlUiRNUVxyd7m7nN3Zuc/pA3kOD9eSzZtkIDnAQEPt7Mz5/vttlmBvMcZMADkAGgCCX67FAMQAeoSQANgDyBgrALAA7ACICCHZe7bF+7AYYxSAAaAAwCeEuGCMmYyxM3sf/lIvxhjdw2pS7Ir3zi8bl++29jC6AHIUuzodvbdbeqArBKBRAORXgdt87WEl6gN8Jp2amspnWTZi23ZVVdUSpdTMsozFcZwkSdLyfX8jy7KNjY0NH7uW+L6t+w2cPvHEE2O6rn+UUvopRVEuUUrP6LpuEEIopbv2NMsyxHHMoijyGWNr1Wr1/7Is+592u/2T9fX1Nu4DEQhjbJQQsnHa93300Uen8vn8F3Rd/z1N084ahkFN04SqqCCUgFIKQggYY2CMIU1TTgD4vo8oipIoihajKPqXTqfzjfX19dZpbY4xNnrqwM+cOeOcPXv2jy3L+pJlWWOmaRJd16HrOjRNA6VUgJaBy+CjKEIYhvB9H0EQZEEQ/MJ13a8sLS39N4D0pHtkjI2epqiTRx99dLZcLv+dbdufNE1TM00Tuq7DNE0YhiGAc9CEEL4RATxNU8RxjDAMYRgGwjCkvu+/T9f1b2qa9tzOzs5XNjY2mifd7GkBp7Ozs58uFov/ZNv2uGVZxLIs6LqOXC4nuK2qKhRFOQAe2NVxxhiyLEOSJEjTFFEUod/vw/M8qKoKSqlDKf0TTdOepJR+fn19ffEkGz4N4HR2dvZ3SqXSVx3HKeVyOViWBcMwYFkWTNOEoih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AN7+y8GBET68FfqNyL+H3ZRI0RYl4zyAAAAAElFTkSuQmCC";

// 将 Base64 数据分割,提取编码后的图片数据部分
const base64Image = base64Data.split(';base64,').pop();

// 写入文件
fs.writeFile('image.png', base64Image, { encoding: 'base64' }, function(err) {
if (err) {
console.error('写入文件失败:', err);
} else {
console.log('文件写入成功!');
}
});

// 使用 FormData 包装文件
const formData = new FormData();
formData.append('image', fs.createReadStream('image.png'));

console.log('formData',formData)