Reputation: 6925
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 are more details with screen shots: https://forums.meteor.com/t/saving-image-with-javascript-node-to-filesystem/21761
Upvotes: 1
Views: 1550
Reputation: 17508
Client
readAsDataURL
has base64 encoded data in the format of
data:image/jpeg;base64,/9j/4AAQSkZJRgABA...
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.
Server
Since you're receiving base64 encoded data, you can convert it buffer and write to file:
fs.writeFile(filepath, Buffer(argument,'base64'), err => {
//
})
Upvotes: 3