1

When I select small files there is no problem. But for big files larger than around 1MB I get Failed to load resource: net::ERR_CONNECTION_RESET on Chromium or NetworkError when attempting to fetch resource on Firefox console and 308 status code on server, whether I use the production server or Gunicorn. Any solution?

JavaScript:

let data = new FormData();
data.append("file", inputFile.files[0]);
let response = await fetch("/upload?key=value", {method: "PUT", body: data});

Python:

@app.put('/upload/')
def upload_file():
    key = request.args['key']
    file = request.files['file']
    print(key)
    print(file)
    return ''

EDIT: I found the problem. The problem is the query string. The following codes work. Now I want to know how can I pass the query string using PUT or POST method to Flask?

New JavaScript:

let data = new FormData();
data.append("file", inputFile.files[0]);
let response = await fetch("/upload/", {method: "PUT", body: data});

New Python:

@app.put('/upload/')
def upload_file():
    file = request.files['file']
    print(file)
    return ''
Dante
  • 611
  • 1
  • 7
  • 21
  • Does this answer your question? [Flask file upload limit](https://stackoverflow.com/questions/19911106/flask-file-upload-limit) – Harun Yilmaz Dec 08 '22 at 15:04
  • I tried it. Does nothing. – Dante Dec 08 '22 at 15:05
  • do you have control on upload_max_filesize in your server's configuration, you need to increase it – Taha Azzabi Dec 08 '22 at 16:07
  • @TahaAzzabi By default Flask will happily accept file uploads with an unlimited amount of memory. Source: https://flask.palletsprojects.com/en/2.2.x/patterns/fileuploads/ – Dante Dec 08 '22 at 16:13

1 Answers1

0

OK. Here is the solution. Just watch out for slashes:

JavaScript code:

let data = new FormData();
data.append("file", inputFile.files[0]);
let response = await fetch("/upload?key=value", {method: "PUT", body: data});

Python code:

@app.put('/upload') # no slash at the end
def upload_file():
    file = request.files['file']
    value = request.args['key']
    print(file)
    print(value)
    return ''

But I do not know why.

Dante
  • 611
  • 1
  • 7
  • 21