如何将 base64data 字符串作为 png 图像保存到服务器?
下面的代码适用于 php,但我使用 nodejs 作为后端。 我通过ajax调用发送base64数据。
list($type, $data) = explode(';', $data);
list(, $data) = explode(',', $data);
$data = base64_decode($data);
file_put_contents('myDirectory/filename.png', $data);
最佳答案
您可以使用filesystem API .
var fs = require('fs');
fs.writeFile("/tmp/test.png", $data, "binary", function(err) {
if(err) {
console.log(err);
} else {
console.log("The file was saved!");
}
});
另请参阅here
关于javascript - 如何将base64数据保存为png图像到服务器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23533781/