0

I have a code like this

Some Controller

def store_report():
    try:
        file = request.files.get('file')
        upload_path = './storage/'

        if allowed_file(file.filename):
            file.save(os.path.join(upload_path, file.filename))
        else:
            return flask.abort(make_response(jsonify(status=400, message='File extension must be image'), 400))

        return make_response(jsonify(status=200, message='Success'), 200)

    except ValueError:
        return flask.make_response(jsonify(message="Error when store", status=400), 400)



def allowed_file(filename):
    return '.' in filename and \
           filename.rsplit('.', 1)[1].lower() in {'png', 'jpg', 'jpeg'}

When i upload file < 500kb, i can get the request.files value. but when i upload >500kb the request.files return nothing or null.

What should i do, so i can upload bigger files?

I want to upload the bigger files for image recognition logic

Briansay
  • 3
  • 2
  • 1
    Does this answer your question? [Handling large file uploads with Flask](https://stackoverflow.com/questions/44727052/handling-large-file-uploads-with-flask) – Drizzle Jul 09 '23 at 15:19
  • Hope this will helps ... https://stackoverflow.com/questions/31873989/rejecting-files-greater-than-a-certain-amount-with-flask-uploads – PRATHEESH PC Jul 10 '23 at 11:58

1 Answers1

0
from flask import Flask, Request

app = Flask(__name__)
app.config['MAX_CONTENT_LENGTH'] = 16 * 1000 * 1000

"The code above will limit the maximum allowed payload to 16 megabytes. If a larger file is transmitted, Flask will raise a RequestEntityTooLarge exception." - Flask Docs
Changing MAX_CONTENT_LENGTH should do the job

TRENWAR
  • 3
  • 4