"The data value transmitted exceeds the capacity limit" flask restX error when I try to post an image file

112 Views Asked by At

I use flask restX for an API and I want to create an endpoint to upload some images using the following code for main.py.The problem I got is that I can't post not even an image in the endpoint. I want to see a good response when I try to post the image.

#app.py
from bson import ObjectId
from flask import Flask
from flask_jwt_extended import JWTManager
from flask_pymongo import PyMongo
import os
from flask_cors import CORS 
from extensions import api, db, jwt  

from namespaces.userController import nsUser
from namespaces.tablesController import nsTables
from namespaces.productsController import nsProducts
from namespaces.loginController import nsLogin
from namespaces.employerController import nsEmployer
from namespaces.uploadController import nsUpload

app = Flask(__name__)
CORS(app)

app.config["MONGO_URI"] = "mongodb+srv://user:[email protected]/?retryWrites=true&w=majority"
app.config["JWT_SECRET_KEY"] = "cookiemonster"

collection = db["user"]

api.init_app(app)
api.add_namespace(nsUser)
api.add_namespace(nsLogin)
api.add_namespace(nsTables)
api.add_namespace(nsProducts)
api.add_namespace(nsEmployer)
api.add_namespace(nsUpload)

mongo = PyMongo(app)
jwt = JWTManager(app)


# JWT Identity Loader
@jwt.user_identity_loader
def user_identity_lookup(user):
    return user["id"]


# JWT User Lookup Callback
@jwt.user_lookup_loader
def user_lookup_callback(jwt_header, jwt_data):
    identity = jwt_data["sub"]

    user = collection.find_one({"_id": ObjectId(identity)})
    return user

if __name__ == "__main__":
    app.run()

Every time when I post an image I get the above error. Even for small images.

{
  "message": "The data value transmitted exceeds the capacity limit."
}
#nsUpload
from flask_restx import Namespace, Resource, reqparse
from werkzeug.datastructures import FileStorage
upload_parser = reqparse.RequestParser()
upload_parser.add_argument('images', location='files',
                           type=FileStorage, required=True, action="append")

nsUpload = Namespace("upload", description="Upload data ")


@nsUpload.route("/ceva")
class ceva(Resource):
    @nsUpload.expect(upload_parser)
    def post(self):
        args = upload_parser.parse_args()
        images = args['images']

How do I manage to upload multiple images using swagger UI from the browser and to add them somewhere?

HOW SHOULD APPEAR WHEN I USE THE ENDPOINT

0

There are 0 best solutions below