'Receive form data (csv files) from reactjs front to Flask back-end
I have a form with multiple inputs (5) to select CSV files and then send them to Flask back end to do something with it, the problem is that the csv FILE is an empty dict when I print it in server side (it happens only with CSV files, I receive with the same code all the other Inputs integers and text)
OUTPUT :
{'selection_des_branchements': {}}
Here is an example on Inputfrom react.js :
> <Input > name="file" > id="csv-file" > multiple > type="file" > accept=".csv" > onChange={(e) => setCsvFile(e.target.files[0])}/> </form>```
This is how I store the data :
const [csvFile, setCsvFile] = useState("") const data = { selection_des_branchements: csvFile, };
And the fetch :
const LancerMiseAJourAnuelle = () => {
setButtonClicked(true);
const data = {
selection_des_branchements: csvFile,
};
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"),
// body : fromData
data,
})
.then((response) => {
console.log(response);
})
.catch((error) => {
console.log(error.response);
});
};
Ans here is my webservice to get the data from the Flask backend :
> @app.route("/Execution_maj_annuelle", methods=["GET", "POST"]) def
> Lancer_Execution_maj_data():
> os.system('clear')
>
> data = request.json['data']
> print(data)
> return (data)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
