Closed GRUXXKi closed 5 years ago
Sorry that it's not mentioned in the docs, but you need an id for the MediaObject
. I'll update the docs to include that.
Please let me know if everything works after that.
Sure, id is mandatory for Entity management. So I've added one already.
Here is my MediaObject entity :
<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiProperty;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Controller\CreateMediaObjectAction;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
/**
* @ORM\Entity
* @ApiResource(iri="http://schema.org/MediaObject", *
* collectionOperations={
* "get",
* "post"={
* "method"="POST",
* "controller"=CreateMediaObjectAction::class,
* "defaults"={"_api_receive"=false},
* "access_control"="is_granted('ROLE_ORGANIZER')||is_granted('ROLE_ADMIN')",
* "validation_groups"={"Default", "media_object_create"}, *
* "swagger_context"={
* "consumes"={
* "multipart/form-data",
* },
* "parameters"={
* {
* "in"="formData",
* "name"="file",
* "type"="file",
* "description"="The file to upload",
* },
* },
* },
* },
* },
* itemOperations={
* "get",
* },
* )
* @Vich\Uploadable
*/
class MediaObject
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @var string|null
*
* @ApiProperty(iri="http://schema.org/contentUrl")
* @Groups({"media_object_read"})
*/
public $contentUrl;
/**
* @var File|null
*
* @Assert\NotNull(groups={"media_object_create"})
* @Vich\UploadableField(mapping="media_object", fileNameProperty="filePath")
*/
public $file;
/**
* @var string|null
*
* @ORM\Column(nullable=true)
*/
public $filePath;
}
Sorry I just saw that my id is private and no get/set....
Addressed in https://github.com/api-platform/docs/pull/786
I've trying to find out what I've been doing wrong but I really can't solved it.
I've installed symfony following the documentation and started to write my code. Everything is really great and after having installed successfully the JWT token, I'm starting to handle the file uploading !
Here is my Symfony.lock :
For test, I've followed exactly the documentation here : https://api-platform.com/docs/core/file-upload/
But now when I try to send something, here is the result I've got:
Any idea ?