Я использую электронный диалог, чтобы получить доступ к файлам пользователя, теперь я хочу загрузить выбранный файл на веб-сервер.В моем коде я использую fs.copyFile
, но он показывает мне ошибку, потому что он добавляет путь к проекту к http://localhost/upload.
Я буду очень рад любой помощи.Спасибо
dialog.showOpenDialog(dialogOptions,function(fileNames) {
// fileNames is an array that contains all the selected
if (fileNames === undefined) {
console.log("No file selected");
} else {
readFile(fileNames[0]);
}
});
function readFile(filepath) {
fs.readFile(filepath, 'utf-8', (err, data) => {
if (err) {
alert("An error ocurred reading the file :" + err.message)
return
}
fileName = pathf.basename(filepath);
// Copy the chosen file to the application's data path
fs.copyFile(filepath, 'http://localhost/upload/' + fileName, (err) => {
if (err) throw err;
});
// handle the file content
event.sender.send('fileData', data)
event.sender.send('fileDataPath', filepath)
})
}