Forum Discussion

harryboy's avatar
harryboy
Occasional Contributor
5 years ago

Swagger OpenAPI3 POST Array of images and media file together

I am using the swagger python-flask framework to create an OpenAPI 3 API which needs to do the following:

1. Upload a video file

2. Upload an array of images

3. Upload extra string data.

I can successfully upload a single file successfully using:

 

 

MyFileUploadAPI:
 post:
  operationId: my_file_upload
  requestBody:
    content:
      multipart/form-data:
        schema:
          $ref: '#/components/schemas/videofile'

components:
  schemas:    
    videofile:
      type: object
      properties:
        upload:
         type: string
         format: binary


# This works fine
def my_file_upload(videofile):  
    file_name = videofile.filename

 

And I can upload an array of images and other data using:

 

MyMultipleImagesUploadAPI:
 post:
  operationId: multiple_files
  requestBody:
    content:
      application/json:
        schema:
          $ref: '#/components/schemas/multiplefiles'
components:
  schemas:    
    multiplefiles:
      type: object
      properties:
        Images:
          items:
            $ref: '#/components/schemas/MyImage'
        TotalCount:
          type: integer

# This works fine
def multiple_files(body):    

    if connexion.request.is_json:
        body = multiplefiles.from_dict(connexion.request.get_json())                
        images = body._images
        count = body._totalcount

 

Now I wish to combine the two together (Video upload + Multiple images + extra data) So I have did the following:

 

/MyEverythingAPI:
post:
  operationId: video_multiple_images
  requestBody:
    content:
      multipart/form-data:
        schema:
          $ref: '#/components/schemas/everything'

components:
  schemas:  
  everything:
    type: object
    properties:
      Video:
        type: string
        format: binary
      Images:
        type: array
        items:
          $ref: '#/components/schemas/MyImage'
      TotalCount:
        type: integer

# This has issues
def video_multiple_images(body, video_clip, **kwargs): 
   #body = {'images': ['[object File]'], 'totalcount': 2}
   uploaded_file_name = video_clip.filename

 

Now there are 2 issues that I see that are just not correct:

 

Issue 1. The video_clip was not getting passed through to the function video_multiple_images.
I debugged and tracked it down and saw that it was not getting added because there were no **kwargs added to my function signature. When I added the **kwargs   then the video file started to get passed through. This post helped me solve that part: https://github.com/zalando/connexion/pull/753/files I can live with this issue but would like to know why this is the case.

Issue 2. The image array is coming through as [object File]''[Object File]'' etc. This post indicates that this is not supported in OpenAPI 3: In Swagger openapi v3.0.0, facing issue in multiple file uploads

 

So how can I pass a video file + an array of images?

No RepliesBe the first to reply