Вы можете сохранить загруженный файл в папке userAppData
. Вы должны попробовать, как показано ниже
function uploadFile() {
dialog.showOpenDialog({
properties: ['openFile','multiSelections'],
filters: [{
name: 'Images',
extensions: ['jpg', 'png', 'gif']
}]
},
uploadF, //define callback
)
}
function uploadF(filePaths) {
if (filePaths!=undefined) {
//multiple image upload
for (let i = 0; i < filePaths.length; i++) {
let fileName = path.basename(filePaths[i])
fileName = moment().unix()+'-'+fileName //rename file
let fileUploadPath = app.getPath('userData')+ '' + fileName;
move(filePaths[i],fileUploadPath,cb)
}
}
}
function cb(e) {
console.log("error in upload file",e);
}
function move(oldPath, newPath, callback) {
fs.rename(oldPath, newPath, function (err) {
if (err) {
if (err.code === 'EXDEV') {
copy();
} else {
console.log("err",err);
callback(err);
}
return;
}
callback();
});
function copy() {
var readStream = fs.createReadStream(oldPath);
var writeStream = fs.createWriteStream(newPath);
readStream.on('error', callback);
writeStream.on('error', callback);
readStream.on('close', function () {
let fileName=path.basename(newPath)
console.log(fileName," file uploaded")
//remove path from destination
//fs.unlink(oldPath, callback);
// do your stuff
});
readStream.pipe(writeStream);
}
}