I am building a small Electron.js application for data processing. I have a renderer process script, that controls the loaded main.html file. The code looks like this:
const { start } = require("repl");
let {PythonShell} =require('python-shell')
var csv = require("csv-reader");
var fs = require("fs");
function WaitForAnalysis(cb) {
const out_plots=document.getElementById("output_plots");
out_plots.style.display = "none"
const start_button = document.getElementById("start");
start_button.addEventListener("click", cb);
};
function bind_data() {
WaitForAnalysis(function(){
console.log("Start")
const input_file = document.getElementById("input_file").files[0];
const design_file = document.getElementById("input_design").files[0];
const seq_col = document.getElementById("Sequence_column").value;
const abun_col = document.getElementById("Abundance_column").value;
const acc_col = document.getElementById("Accession_column").value;
console.log(input_file)
//Create Read stream for datafile
fs.readFile(input_file.path,function (data){
console.log(data)
let data1 = {
"file1":data,
"file2":design_file,
"seq_col":seq_col,
"abun_col":abun_col,
"acc_col":acc_col
}
let pyshell = new PythonShell('./PBLMM.py',{pythonPath : 'python'});
pyshell.send(JSON.stringify(data1),{mode:'json'});
pyshell.on('message', function(message) {
console.log(message)
})
})})
};
document.addEventListener("DOMContentLoaded", bind_data)
After the user selected the files on the GUI, the file should be read in. However I am facing problems with reading the files. In the Dev-Console i get the File object, when i log my input_file
variable.
As suggested here: Similar Question the file object indeed has this attribute:
File {name: "CCCP_LMM_result.csv", path: "C:UsersKevinDesktopMassSpecImport_LMMCCCP_LMM_result.csv", lastModified: 1611247811744, lastModifiedDate: Thu Jan 21 2021 17:50:11 GMT+0100 (Central European Standard Time), webkitRelativePath: "", …}
However, when i try to access it by input_file.path
or document.getElementById("input_file").files[0].path
then i get undefined
Does anyone have a solution for this?
question from:
https://stackoverflow.com/questions/65833002/read-file-from-input-form-to-electron-nodejs-problem 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…