in my Electron app I need to upload a file (.mp3) using a normal html input
and then save it on the disk.
I'm reading the file using the browser's FileReader:
const reader = new FileReader();
reader.onload = () => {
resolver.next(reader.result as string);
resolver.complete();
};
reader.readAsBinaryString(file);
Then I sent the readed content like this:
this.electronService.ipcRenderer.on('aaaSuccess', (_, newPath) =>
this.store$.dispatch(HomeActions.changeSuccess({ soundName: action.sound.name, newPath })));
this.electronService.ipcRenderer.send('aaa', { fileName: file.name, content: base64 });
Then I pass the readed binary string to the mainProcess like this:
ipcMain.on('aaa', (event, { fileName, content }) => {
var newPath = path.join(app.getPath('userData'), fileName);
fs.writeFile(newPath, content, function (err) {
if (err) { return console.log('error is writing new file', err) }
event.reply('aaaSuccess', newPath)
});
})
This code works, but the dimension in bytes of the saved file is different from the original one, and it can't be opened using an mp3 player
Thanks a lot