У меня есть приложение React Electron, в котором пользователь может перетаскивать файлы на переднем конечном компоненте React, и эти файлы отправляются на бэкэнд через функцию рендеринга IPC.
Мне нужно иметь возможность получить Полный залив для этих отброшенных файлов из бэкэнд Main.js Electron Process, но я не могу понять, как это сделать. < /p>
const handleDrop = async (event) => {
// Get dropped files
event.preventDefault();
const droppedFiles = Array.from(event.dataTransfer.files);
console.log('Dropped files:', droppedFiles);
// Send dropped files to backend main.js process
window.api.send('get-filepaths', droppedFiles);
// Handle returned file paths
window.api.receive('get-filepaths-response', ( filepathsRsp ) => {
console.log('Received file paths:', filepathsRsp);
});
}
< /code>
Вы можете увидеть на передней части, мое приложение React распечатывает данные о выпущенном файле, а FilePath нет.
Тогда в бэкэнге Main.js получены FilePaths, но как мне в этом Main.js Код ниже Получите FilePath для этих файлов? < /p>
ipcMain.on('get-filepaths', (event, files) => {
console.log('get-filepaths: ', files);
// Get filepaths for each file
files.forEach(file => {
console.log('file = ', file.name)
});
// Send filepaths back to front end
event.reply('get-filepaths-response', ['filepath1','filepath2']);
});
< /code>
get-filepaths: [ {}, {}, {} ]
file = undefined
file = undefined
file = undefined
< /code>
How can I get the filepath from these files in my backend main.js?
I see in the electron docs online a section for how to do this with Renderer Process Modules, but I cant find any info on how to do this with Main Process Modules https://www.electronjs.org/docs/latest/api/web-utils
All my code is on the main branch here:
https://github.com/MartinBarker/electro ... -file-drop
Подробнее здесь: https://stackoverflow.com/questions/794 ... in-process