Currently, I want to upload some pictures from the frontend to the backend, and I can upload these images correctly, but I don't know how to get these photos in the backend. Here, I upload the images using FormData in the frontend
const url = "http://localhost:5000/hotel";
const data = new FormData();
var photos = document.querySelector("input[type='file'][multiple]");
console.log(photos.files);
data.append("photos", photos.files);
fetch(url, {
headers: new Headers({
"Content-Type": "application/json"
}),
mode: "cors",
method: "post",
body: data
});
now, I tried to get these files in the backend using flask.
@app.route('/hotel', methods=['POST'])
def add_hotel():
print(request.form)
print(request.data)
print(request.files)
The print result is something like this:
ImmutableMultiDict([])
b'------WebKitFormBoundaryo54yZ5CoNX8dQZZ3\r\nContent-Disposition: form-data; name="photos"\r\n\r\n[object FileList]\r\n------WebKitFormBoundaryo54yZ5CoNX8dQZZ3--\r\n'
ImmutableMultiDict([])
and I think these images are stored in the request.data, but how can I save these data like the normal file in request.files?