@@ -25,6 +25,7 @@ to make it look like this.
25
25
26
26
``` yaml
27
27
# api/config/packages/vich_uploader.yaml
28
+
28
29
vich_uploader :
29
30
db_driver : orm
30
31
metadata :
@@ -34,7 +35,7 @@ vich_uploader:
34
35
uri_prefix : /media
35
36
upload_destination : ' %kernel.project_dir%/public/media'
36
37
# Will rename uploaded files using a uniqueid as a prefix.
37
- namer : Vich\UploaderBundle\Naming\OrignameNamer
38
+ namer : Vich\UploaderBundle\Naming\SmartUniqueNamer
38
39
` ` `
39
40
40
41
## Uploading to a Dedicated Resource
@@ -53,6 +54,7 @@ The `MediaObject` resource is implemented like this:
53
54
` ` ` php
54
55
<?php
55
56
// api/src/Entity/MediaObject.php
57
+
56
58
namespace App\E ntity;
57
59
58
60
use ApiPlatform\M etadata\A piProperty;
@@ -109,7 +111,7 @@ class MediaObject
109
111
#[Groups(['media_object:read'])]
110
112
public ?string $contentUrl = null;
111
113
112
- #[Vich\Uploadabl eField(mapping: " media_object" , fileNameProperty: " filePath" )]
114
+ #[Vich\Uploadabl eField(mapping: ' media_object' , fileNameProperty: ' filePath' )]
113
115
#[Assert\N otNull(groups: ['media_object_create'])]
114
116
public ?File $file = null;
115
117
@@ -172,12 +174,11 @@ A [normalizer](serialization.md#normalization) could be used to set the `content
172
174
namespace App\S erializer;
173
175
174
176
use App\E ntity\M ediaObject;
175
- use Symfony\C omponent\S erializer\N ormalizer\C ontextAwareNormalizerInterface;
176
177
use Symfony\C omponent\S erializer\N ormalizer\N ormalizerAwareInterface;
177
178
use Symfony\C omponent\S erializer\N ormalizer\N ormalizerAwareTrait;
178
179
use Vich\UploaderB undle\S torage\S torageInterface;
179
180
180
- final class MediaObjectNormalizer implements ContextAwareNormalizerInterface, NormalizerAwareInterface
181
+ final class MediaObjectNormalizer implements NormalizerAwareInterface
181
182
{
182
183
use NormalizerAwareTrait;
183
184
@@ -246,6 +247,7 @@ We first need to edit our Book resource, and add a new property called `image`.
246
247
``` php
247
248
<?php
248
249
// api/src/Entity/Book.php
250
+
249
251
namespace App\Entity;
250
252
251
253
use ApiPlatform\Metadata\ApiResource;
@@ -406,7 +408,9 @@ final class MultipartDecoder implements DecoderInterface
406
408
{
407
409
public const FORMAT = 'multipart';
408
410
409
- public function __construct(private RequestStack $requestStack) {}
411
+ public function __construct(private RequestStack $requestStack)
412
+ {
413
+ }
410
414
411
415
/**
412
416
* {@inheritdoc}
@@ -452,17 +456,11 @@ use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
452
456
453
457
final class UploadedFileDenormalizer implements DenormalizerInterface
454
458
{
455
- /**
456
- * {@inheritdoc}
457
- */
458
459
public function denormalize($data, string $type, string $format = null, array $context = []): UploadedFile
459
460
{
460
461
return $data;
461
462
}
462
463
463
- /**
464
- * {@inheritdoc}
465
- */
466
464
public function supportsDenormalization($data, $type, $format = null): bool
467
465
{
468
466
return $data instanceof UploadedFile;
0 commit comments