Saving Image with JavaScript / Node to FileSystem



I write some code for image uploading and I have a problem with saving the image file to local file system.

As you can see on screenshots Code creates a file on my location but a file is not readable.

Do I miss something in a process of saving?

Here is Client and Server Code Screenshot:

Here is error and you can see in back encoding/decoding result it seems okay.




readAsDataURL has base64 encoded data in the format of

So you need to get rid of the mime type and encoding information at the front.

contents = contents.split(’,’)[1];
Now you can send this base64 encoded data to server.


Since you’re receiving base64 encoded data, you can convert it buffer and write to file:

fs.writeFile(filepath, Buffer(argument,‘base64’), err => {

Hassansin give me correct solution on: