0

How can i save a base64data string as png image to server?

Below code is for php but i am using nodejs as backend. I am sending base64data through ajax call.

list($type, $data) = explode(';', $data);
list(, $data)      = explode(',', $data);
$data = base64_decode($data);
file_put_contents('myDirectory/filename.png', $data);
TeamA1
  • 193
  • 1
  • 3
  • 11
  • Decode the base64 data. Write the data to a file - Now you know the steps, search for how to accomplish each individually, and then combine them. There is no problem here, only a request for code translation. – user2864740 May 08 '14 at 05:56

1 Answers1

1

You can use the 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!");
  }
});

Also see here

Nisanth Sojan
  • 1,099
  • 8
  • 21