core icon indicating copy to clipboard operation
core copied to clipboard

Multiple upload files bug

Open kovlcode opened this issue 6 years ago • 1 comments

API Platform version(s) affected: 2.5.4

Description I need multiple file uploads for one time. It seems that submitting a form with multiple file uploads does not work correctly.

To upload one file, I use the following description:

<?php
declare(strict_types=1);

namespace App\Entity;

// use ...

/**
 * @ApiResource(
 *     iri="http://schema.org/MediaObject",
 *     itemOperations={
 *         "get"
 *     },
 *     collectionOperations={
 *         "get",
 *         "post" = {
 *             "controller" = MediaHandler::class,
 *             "deserialize" = false,
 *             "security" = "is_granted('ROLE_USER')",
 *             "validation_groups" = {"Default", "media:collection:post"},
 *             "openapi_context" = {
 *                 "requestBody" = {
 *                     "content" = {
 *                         "multipart/form-data" = {
 *                             "schema" = {
 *                                 "type" = "object",
 *                                 "properties" = {
 *                                     "file" = {
 *                                         "type" = "string",
 *                                         "format" = "binary"
 *                                     }
 *                                 }
 *                             }
 *                         }
 *                     }
 *                 }
 *             }
 *         }
 *     },
 *     //...
 */
class Media
{
    //...
}

It works great.

For upload multiple files, I use the next description (https://swagger.io/docs/specification/describing-request-body/file-upload/#multiple):

// ...

 *                 "requestBody" = {
 *                     "content" = {
 *                         "multipart/form-data" = {
 *                             "schema" = {
 *                                 "type" = "object",
 *                                 "properties" = {
 *                                     "file" = {
 *                                         "type" = "array",
 *                                         "items" = {
 *                                             "type" = "string",
 *                                             "format" = "binary"
 *                                         }
 *                                     }
 *                                 }
 *                             }
 *                         }
 *                     }
 *                 }

// ...

After that, I select several files and try to send them to the server. But my curl request looks like this:

curl -X POST "https://mydomain.com/api/test" -H  "accept: application/ld+json" -H  "Authorization: Bearer  <bearer token>" -H  "Content-Type: multipart/form-data" -F "file=[object File],[object File]"

Platform generated -F "file=[object File],[object File]" request, without something like -F "file[][email protected];type=image/jpeg" -F "file[][email protected];type=image/jpeg" On server variable $_FILES empty.

Maybe I'm doing something wrong, but it looks like a bug.

kovlcode avatar Mar 10 '20 16:03 kovlcode

@winzza https://github.com/swagger-api/swagger-ui/issues/4600

xeurun avatar Jun 18 '20 10:06 xeurun