Skip to content

Commit c5bee05

Browse files
authored
remove a deprecation in upload docs (#1871)
1 parent d2f5e74 commit c5bee05

File tree

1 file changed

+25
-15
lines changed

1 file changed

+25
-15
lines changed

core/file-upload.md

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ to make it look like this.
2525

2626
```yaml
2727
# api/config/packages/vich_uploader.yaml
28+
2829
vich_uploader:
2930
db_driver: orm
3031
metadata:
@@ -34,7 +35,7 @@ vich_uploader:
3435
uri_prefix: /media
3536
upload_destination: '%kernel.project_dir%/public/media'
3637
# Will rename uploaded files using a uniqueid as a prefix.
37-
namer: Vich\UploaderBundle\Naming\OrignameNamer
38+
namer: Vich\UploaderBundle\Naming\SmartUniqueNamer
3839
```
3940
4041
## Uploading to a Dedicated Resource
@@ -53,6 +54,7 @@ The `MediaObject` resource is implemented like this:
5354
```php
5455
<?php
5556
// api/src/Entity/MediaObject.php
57+
5658
namespace App\Entity;
5759
5860
use ApiPlatform\Metadata\ApiProperty;
@@ -109,7 +111,7 @@ class MediaObject
109111
#[Groups(['media_object:read'])]
110112
public ?string $contentUrl = null;
111113
112-
#[Vich\UploadableField(mapping: "media_object", fileNameProperty: "filePath")]
114+
#[Vich\UploadableField(mapping: 'media_object', fileNameProperty: 'filePath')]
113115
#[Assert\NotNull(groups: ['media_object_create'])]
114116
public ?File $file = null;
115117
@@ -172,12 +174,11 @@ A [normalizer](serialization.md#normalization) could be used to set the `content
172174
namespace App\Serializer;
173175
174176
use App\Entity\MediaObject;
175-
use Symfony\Component\Serializer\Normalizer\ContextAwareNormalizerInterface;
176177
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
177178
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
178179
use Vich\UploaderBundle\Storage\StorageInterface;
179180
180-
final class MediaObjectNormalizer implements ContextAwareNormalizerInterface, NormalizerAwareInterface
181+
final class MediaObjectNormalizer implements NormalizerAwareInterface
181182
{
182183
use NormalizerAwareTrait;
183184
@@ -224,17 +225,23 @@ your data, you will get a response looking like this:
224225

225226
### Accessing Your Media Objects Directly
226227

227-
You will need to modify your Caddyfile to allow the above `contentUrl` to be accessed directly. If you followed the above configuration for the VichUploaderBundle, that will be in `api/public/media`. Add your folder to the list of path matches, e.g. `|^/media/|`:
228-
229-
```caddyfile
230-
...
231-
# Matches requests for HTML documents, for static files and for Next.js files,
232-
# except for known API paths and paths with extensions handled by API Platform
233-
@pwa expression `(
234-
{header.Accept}.matches("\\btext/html\\b")
235-
&& !{path}.matches("(?i)(?:^/docs|^/graphql|^/bundles/|^/media/|^/_profiler|^/_wdt|\\.(?:json|html$|csv$|ya?ml$|xml$))")
236-
...
228+
You will need to modify your `Caddyfile` to allow the above `contentUrl` to be accessed directly. If you followed the above configuration for the VichUploaderBundle, that will be in `api/public/media`. Add your folder to the list of path matches, e.g. `|^/media/|`:
229+
230+
<!-- markdownlint-disable no-hard-tabs -->
231+
```patch
232+
# Matches requests for HTML documents, for static files and for Next.js files,
233+
# except for known API paths and paths with extensions handled by API Platform
234+
@pwa expression `(
235+
header({'Accept': '*text/html*'})
236+
&& !path(
237+
- '/docs*', '/graphql*', '/bundles*', '/media*', '/contexts*', '/_profiler*', '/_wdt*',
238+
+ '/media*', '/docs*', '/graphql*', '/bundles*', '/media*', '/contexts*', '/_profiler*', '/_wdt*',
239+
'*.json*', '*.html', '*.csv', '*.yml', '*.yaml', '*.xml'
240+
)
241+
)
242+
|| path('/favicon.ico', '/manifest.json', '/robots.txt', '/_next*', '/sitemap*')`
237243
```
244+
<!-- markdownlint-enable no-hard-tabs -->
238245

239246
### Linking a MediaObject Resource to Another Resource
240247

@@ -246,6 +253,7 @@ We first need to edit our Book resource, and add a new property called `image`.
246253
```php
247254
<?php
248255
// api/src/Entity/Book.php
256+
249257
namespace App\Entity;
250258

251259
use ApiPlatform\Metadata\ApiResource;
@@ -406,7 +414,9 @@ final class MultipartDecoder implements DecoderInterface
406414
{
407415
public const FORMAT = 'multipart';
408416

409-
public function __construct(private RequestStack $requestStack) {}
417+
public function __construct(private RequestStack $requestStack)
418+
{
419+
}
410420

411421
public function decode(string $data, string $format, array $context = []): ?array
412422
{

0 commit comments

Comments
 (0)