Flask-apispec에서 파일 업로드 처리

2023. 6. 21. 00:40서버 프로그래밍

내가 원한건 파일 업로드를 위한 POST API를 Swagger UI에서 테스트할 수 있도록 하는것인데 정말 쓸만한 레퍼런스가 없다. 이 간단한 코드를 만들기 위해 여기 저기서 짜깁기를 해야하다니.. 헐

from flask_apispec import marshal_with, use_kwargs
from flask_apispec.views import MethodResource
from marshmallow import Schema, fields
from werkzeug.datastructures import FileStorage

@use_kwargs({"file": fields.Raw(type="file")}, location="files")
@marshal_with(ResponseSchema)
def post(self, file: FileStorage):
 :

https://marshmallow.readthedocs.io/en/stable/marshmallow.fields.html

 

Fields — marshmallow 3.19.0 documentation

Fields Field classes for various types of data. Classes: AwareDateTime([format, default_timezone]) A formatted aware datetime string. Bool alias of Boolean Boolean(*[, truthy, falsy]) A boolean field. Constant(constant, **kwargs) A field that (de)seria

marshmallow.readthedocs.io

https://stackoverflow.com/questions/67741946/how-to-validate-fields-raw-in-flask-marshmallow

 

How to validate Fields.Raw in Flask Marshmallow

I'm trying to set up a Webservice that accepts Images via POST methods. I'm using Python Flask as well as Flask-Apispec to create a Swagger documentation. I thus include this Marshmallow Schema to ...

stackoverflow.com

https://github.com/marshmallow-code/webargs/issues/230

 

Docs: Add example for parsing files · Issue #230 · marshmallow-code/webargs

Hey guys, I've been consulting the documentation and the web for a proper solution to parse file arguments from a post request using webargs, but still couldn't find an answer to my question. The d...

github.com

https://github.com/marshmallow-code/apispec/issues/149

 

Question: How to set 'consumes' for file upload operations · Issue #149 · marshmallow-code/apispec

Hi, i am trying to create a file upload endpoint within a flask app. I am using a custom field to enable the fileupload in swagger-ui: @swagger.map_to_swagger_type('file', None) class FileUploadFie...

github.com

https://github.com/jmcarp/flask-apispec/issues/122

 

File upload field declaration in Swagger · Issue #122 · jmcarp/flask-apispec

I recently needed a Swagger 2.0 API endpoint to receive a file upload, and Swagger UI wouldn't show the file input button until I declared it correctly. Maybe this should go into the docs, but unti...

github.com