简体   繁体   English

如何将base64数据作为png图像保存到服务器?

[英]How to save base64 data as png image to server?

How can i save a base64data string as png image to server? 如何将base64data字符串作为png图像保存到服务器?

Below code is for php but i am using nodejs as backend. 下面的代码适用于php,但我使用的是nodejs作为后端。 I am sending base64data through ajax call. 我正在通过ajax调用发送base64data。

list($type, $data) = explode(';', $data);
list(, $data)      = explode(',', $data);
$data = base64_decode($data);
file_put_contents('myDirectory/filename.png', $data);

You can use the filesystem API . 您可以使用文件系统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!");
  }
});

Also see here 也请看这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM