Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fileUploader not working - Error: Unexpected end of form #850

Open
Bec-k opened this issue May 26, 2023 · 3 comments
Open

fileUploader not working - Error: Unexpected end of form #850

Bec-k opened this issue May 26, 2023 · 3 comments

Comments

@Bec-k
Copy link

Bec-k commented May 26, 2023

Using version ^5.0.4

Describe the bug
File upload is failing and throws an error:

Error: Unexpected end of form
    at Multipart._final (/var/local/acp/dashboards/node_modules/busboy/lib/types/multipart.js:588:17)
    at callFinal (node:internal/streams/writable:698:12)
    at prefinish (node:internal/streams/writable:710:7)
    at finishMaybe (node:internal/streams/writable:720:5)
    at Multipart.Writable.end (node:internal/streams/writable:634:5)
    at onend (node:internal/streams/readable:705:10)
    at processTicksAndRejections (node:internal/process/task_queues:77:11)

To Reproduce
Steps to reproduce the behavior.
When specifying middleware with fileUploader: true:

middleware({
    apiSpec,
    fileUploader: true
})

and using below curl:
curl -X POST -F "file=@report.pdf" http://localhost:8001/docs/upload

Actual behavior
File uploading is not working.

Expected behavior
File uploading is working as expected.

Examples and context

  /docs/upload:
    post:
      summary: Upload a single PDF file
      operationId: DocsUpload
      requestBody:
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                file:
                  type: string
                  format: binary
                  description: The pdf document to upload.
@Bec-k
Copy link
Author

Bec-k commented May 26, 2023

Everything is working if path added to ignore list or fileUploader set to false.

@rajathmantis
Copy link

rajathmantis commented Jun 15, 2023

Validation for the form-data can't be handled with this library, it's a headache to use another validation library to handle APIs specifically which are of form-data. I urge the community to handle the form-data requests as well

/**
 * @swagger
 * /admin/picture:
 *   post:
 *     tags:
 *       - Admin
 *     summary: Upload pictures as an admin
 *     description: Upload pictures as an admin
 *     operationId: uploadPictures
 *     requestBody:
 *       required: true
 *       content:
 *         multipart/form-data:
 *           schema:
 *             type: object
 *             properties:
 *               picture:
 *                 type: array
 *                 maxItems: 3
 *                 items:
 *                   type: string
 *                   format: binary
 *               caption:
 *                 type: string
 *             required:
 *               - picture
 *               - caption
 *     responses:
 *       "201":
 *         $ref: "#/components/responses/ServerResponse"
 *       "401":
 *         $ref: "#/components/responses/UnauthorizedResponse"
 *       "404":
 *         $ref: "#/components/responses/NotFoundResponse"
 *       "403":
 *         $ref: "#/components/responses/ForbiddenResponse"
 *       "400":
 *         $ref: "#/components/responses/InvalidInputResponse"
 *       "500":
 *         $ref: "#/components/responses/ServerErrorResponse"
 *     security:
 *       - api_key: []
 *       - bearerAuth: [] 
 */

Issue
The validation for the /admin/picture endpoint is not working as expected when only a single file is sent in the request. The OpenAPI specification defines the picture property as an array of files, but the validation treats it as a string when a single file is sent.

Actual behavior
The validation treats the picture field as a string when a single file is sent in the request, instead of treating it as an array.

Expected behavior
The validation should correctly treat the picture field as an array when either a single file or multiple files are sent in the request.

@gary-menzel
Copy link

I am watching this issue as well. Have just ignored the relevant path for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants