question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Multiple file upload - Got 400

See original GitHub issue

Hello,

In Open API V3 specs, it is possible to specify how multiple file upload is handled ( https://swagger.io/docs/specification/describing-request-body/file-upload/ ).

      requestBody:
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                filename:
                  type: array
                  items:
                    type: string
                    format: binary

After that, I documented the following endpoint ( that does a bulk insert of exercises with their zip files sources ) :

  /api/bulk_create_exercises:
    post:
      summary: "Creates multiple exercises into the system"
      operationId: createMultipleExercises
      security:
        - bearerAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/MultipleExercisesForm"
          multipart/form-data:
            schema:
              type: object
              properties:
                exercisesData:
                  $ref: "#/components/schemas/MultipleExercisesForm"
                files:
                  type: array
                  description: "The sources of the exercises, each in zip format"
                  minItems: 1
                  items:
                    type: string
                    format: binary
                    description: "The source of an exercise, in zip format"
                filesMapping:
                  type: array
                  description: "Mapping between the given file (to find out which data belong to exercise)"
                  minItems: 1
                  items:
                    type: object
                    properties:
                      filename:
                        type: string
                        description: "The name of the given source file"
                        example: "file1.zip"
                      exercise:
                        type: integer
                        description: "The location of the related exercise in the exercisesData array"
                    required:
                      - filename
                      - exercise
              required:
                - exercisesData
                - files
                - filesMapping
      responses:
        '200':
          description: OK
        # Definition of all error statuses
        default:
          description: "Whatever error : 4XX - Client error (Bad Request, Unauthorized, etc.) , 5XX - Server error"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorObject"

I expected this to work but I got a nice 400 error : image

When I look up inside the req before my error handler throws the 400 status code, I see that :

upload3

And the files are correctly uploaded :

upload4

I checked in the tests and there is only single upload tests

Thanks for your help 😉

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
cdimasciocommented, Dec 14, 2019

@jy95 thanks for the PR! your work is a nice improvement over what is current. the change is merged and available in v3.2.2. thanks again!

0reactions
kulkarnipradnyascommented, Jun 14, 2021

from request body i am sending a property files with correct type:string format:binary but still my validator is failing with 500 and in error as well in body object i cant see files property.I am not able to upload file.what is the solution? using latest version of this package.

Read more comments on GitHub >

github_iconTop Results From Across the Web

400 Bad request while uploading multiple files in Spring MVC ...
After form submission, i get an error 400 bad Request. I'm attaching the snapshot of my post parameters as well. Files are getting...
Read more >
Bad Request 400 on file upload - Atlassian Community
My file (.csv) is 2.58MB and I continue to receive the 400 error. Isn't the file limit 100MB? The total lines in this...
Read more >
Multiple file upload field getting HTTP status code 502 error ...
Multiple file upload field getting HTTP status code 502 error when uploading large ... I've tried to upload a 400MB video file and...
Read more >
Canvas File Upload 400 Error: Request failed with status code ...
Our support team was able to increase the quota and file uploading worked like normal once again. Have you encountered this error? Did...
Read more >
Restrictions and limitations in OneDrive and SharePoint
Files that are used by your local computer, such as desktop.ini on Windows or .ds_store on macOS, don't normally sync. If these files...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found