'How to get CSV path from Input and send to Flask Backend
I need to get CSV path chosen by the user (from a react/js Input) and then inject it to flask back-end where I already have functions that receive the CSV path and do the work..
Something like :
@app.route("/Execution_maj_annuelle", methods=["GET", "POST"])
def Lancer_Execution_maj_data():
os.system('clear')
data = request.json['data']
csvData = pd.read_csv(data)
return (csvData)
Ans this is my Input :
const [csvFile, setCsvFile] = useState("");
const data = {
selection_des_branchements: csvFile,
};
<Input
name="file"
id="csv-file"
multiple
type="file"
accept=".csv"
onChange={(e) => setCsvFile(e.target.files[0])}
/>
And my fetch :
axios
.post("http://127.0.0.1:5000/Execution_maj_annuelle", {
cache: false,
contentType: false,
processData: false,
mode: "no-cors",
credentials: "include",
headers:
("Content-Type",
"application/json",
"Origin",
"http://localhost:3000",
"Accept",
"application/json",
"Access-Control-Allow-Headers",
"Origin",
"X-Requested-With"),
data,
})
.then((response) => {
console.log(response);
})
.catch((error) => {
console.log(error.response);
});
};
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|