Open hhllcks opened 6 years ago
It seems that my problem could lie somewhere else. It seems that the swagger ui does not upload the files correctly.
If you curl myself like this everything works fine:
curl -X POST "http://localhost:5000/upload" -H "accept: application/json" -F "file=@5.png"
The questions is then: why does swagger ui create a curl call that looks like this:
curl -X POST "http://localhost:5000/digit" -H "accept: application/json" -H "Content-Type: application/json" -d {"file":{}}
Why does it want to send it as json?
I'm experiencing the exact same error. And I also think that the problem is on the SwaggerUI part of flask-restplus since it generates this wrong curl call.. Please solve this issue since it's very annoying to upload the file per terminal and then test the rest of the API in the SwaggerUI I build a WebApp where I upload the file from a standard HTML Form and it works perfectly fine.
+1 here. Currently using Postman as a workaround (as described here) . Would love to see this solved as well!
+1, also facing the same problem
+1 same problem
+1 same problem
Does anyone found a solution to this? Same problem here
issue was genrated in june 2018 and we are still facing this issue.
This is my code in my case, I use reqparse from flask_restplus parser.py
import werkzeug
from flask_restplus import reqparse
image_upload = reqparse.RequestParser()
image_upload.add_argument('propic',
type=werkzeug.datastructures.FileStorage,
location='files',
required=True,
help='Image file cannot empty')
image_resource.py
@namespace_user.expect(parser.image_upload) #namespace maybe could change to api from flask_restplus
def put(self):
output = {}
img_arg = 'propic'
args = parser.image_upload.parse_args()
if args[img_arg].mimetype == 'multipart/form-data' or args[img_arg].mimetype == 'image/png':
data_user_propics_path = 'data/propics/'
destination = os.path.join(os.path.dirname(os.path.abspath(__file__)),data_user_propics_path)
if not os.path.exists(destination):
os.makedirs(destination)
img_hash_filename = hash_filename_by_md5("something_what_you_want")
img_file = '%s%s' % (destination, img_hash_filename)
try:
args[img_arg].save(img_file)
return make_response(jsonify({
'url': img_file
}), 201)
except Exception as e:
print(e)
return make_response(jsonify({
'message': 'image storage error'
}), 500)
else:
return make_response(jsonify({
'message': 'image type error'
}), 401)
and it's work fine.
also meet the same problem, any work around?
Any update on this issue? Facing the same problem here
When making a front-end request, try to remove the header configuration and keep the default header
Hi,
it seems that using the parameter required=True for a FileUpload like it is shown in the documentation does not seem to work. If the parameter is set, I get the following error:
If the parameter is not there, everything works fine.
I am using Flask 1.0.2 and Flask_restplus 0.11.0.
Here is the full code of my example: