I'm trying to implement a file uploader, where a HTML input file is sent by a WebSocket to a Nodejs server.
Tried to read the file in a BLOB and binary string from the FileReader API of HTML and sent it to Nodejs server so it can be written to a file in the server. Tried createWriteStream and writeFile with ascii or base 64 encoding in the Nodejs part.
Still the file saved in server doesn't work properly.
Am I missing something?
Thank you
UPDATE
Client
var uploader = $("#uploader"),
files = uploader.prop('files'),
file_reader = new FileReader();
file_reader.onload = function(evt) {
socketClient.write({
'action': 'ExtensionSettings->upload',
'domain': structureUser.domain,
'v_id': ext,
'file': file_reader.result
});
};
file_reader.readAsDataURL(files[0]);
//readAsDataURL
uploader.replaceWith(uploader.clone());
Server
var stream = fs.createWriteStream("file");
stream.once("open", function() {
stream.write(msg.file, "base64");
stream.on('finish', function() {
stream.close();
});
});