Flask Restplus Issue with File Upload

Viewed 438

I've been searching for a solution to this issue with little luck. I need to be able to upload an images to the Flask RESTplus API but every time I try I get a 400 Bad Request error with the following snippet:

{
  "errors": {
    "file": "label images Missing required parameter in an uploaded file"
  },
  "message": "Input payload validation failed"
}

Below is the code I'm using. If its any relevance, I'm hosting this Flask program on a docker image.

import werkzeug
from flask import Flask, send_file
from flask_restplus import Resource, Api, namespace
import os

# Declare API
app = Flask(__name__)
api = Api(app)
app.config["DEBUG"] = True

UPLOAD_FOLDER = 'temp/data'

upload_parser = api.parser()
upload_parser.add_argument('file',
                           type=werkzeug.FileStorage,
                           location='files',
                           required=True,
                           help='label images',
                           action='append')

ns_ocr = api.namespace('label_ocr', description='Methods for label OCR.')


# Upload method
@api.route('/upload/')
class UploadImage(Resource):
    @api.expect(upload_parser)
    def post(self):
        args = upload_parser.parse_args()

        uploaded_file = args['file']

        filename = 'picture.jpg'
        uploaded_file.save(os.path.join(UPLOAD_FOLDER, filename))
        return {}, 201
0 Answers
Related