Skip to content

Large JSON is truncated for over 1MB in Flask #3499

@debugsoul

Description

@debugsoul

I am not sure this is a bug or I am missing something, I see several blogs I don't find anything at all and all these objects being accepted for any size in .net core as well in Node but when I tried with flask it's not accepting large size of the JSON object. I don't think MAX_CONTENT_LENGTH is playing any roles in this. FYI I am not trying to upload a file, I just want to pass large JSON Object over the server, I tried in both Dev vs Prod mode same behavior.

Expected Behavior

This should accept all the content from the JSON Objects.

I was using the following JSON as well with larger it's accepting until 1.1MB over it will get truncated and the request was made from the angular application.

(https://github.com/pallets/flask/files/4183314/accepted.txt) -- successfully received. 
(https://github.com/pallets/flask/files/4183315/rejected.txt)  -- rejected

Actual Behavior

 The object being truncated after 1mb size. 

Startup

from flask import Flask, render_template, Blueprint

from flask_cors import CORS


def create_app():
    app = Flask(__name__)
    CORS(app, resources={r"/api/*": {"origins": "*"}})
    app.config['SECRET_KEY'] = "secret!"
    app.config['DEBUG'] = False
    app.config['MAX_CONTENT_LENGTH'] = 1600 * 1024 * 1024
    app.register_blueprint(bp)

    return app

obj = create_app()

if __name__ == '__main__':
    obj.run()

Blueprint

from flask import Blueprint, request

bp = Blueprint('bp', __name__, url_prefix='/image')

@bp.route('PostImage', methods=['POST'])
def PostImage():
    print(request.data)
    print('text')
    return 'test', 200

Environment

  • Python version: 3.6

  • Flask version: 1.1.1

  • Werkzeug version: 1.0.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions