You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* docs: remove processor for file uploading
Remove processor class from file uploading documentation since Vich manage the file creation and set the filePath
* chore: typo in MediaObjectNormalizer.php
* remove unnecessary line
---------
Co-authored-by: soyuka <[email protected]>
Copy file name to clipboardExpand all lines: core/file-upload.md
+5-56Lines changed: 5 additions & 56 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,18 +11,10 @@ before proceeding. It will help you get a grasp on how the bundle works, and why
11
11
**Note**: Uploading files won't work in `PUT` or `PATCH` requests, you must use `POST` method to upload files.
12
12
See [the related issue on Symfony](https://github.com/symfony/symfony/issues/9226) and [the related bug in PHP](https://bugs.php.net/bug.php?id=55815) talking about this behavior.
13
13
14
-
Previously to API Platform 3.3, file upload was using controllers that needs:
14
+
Enable the multipart format globally in order to use it as the input format of your resource:
15
15
16
16
```yaml
17
17
api_platform:
18
-
use_symfony_listeners: true
19
-
```
20
-
21
-
Since 3.3, we recommend to use a Processor, note that you need to enable the multipart format globally:
22
-
23
-
```yaml
24
-
api_platform:
25
-
use_symfony_listeners: false
26
18
formats:
27
19
multipart: ['multipart/form-data']
28
20
jsonld: ['application/ld+json']
@@ -61,9 +53,6 @@ In this example, we will create a `MediaObject` API resource. We will post files
61
53
to this resource endpoint, and then link the newly created resource to another
62
54
resource (in our case: `Book`).
63
55
64
-
This example will use a custom controller to receive the file.
65
-
The second example will use a custom `multipart/form-data` decoder to deserialize the resource instead.
66
-
67
56
### Configuring the Resource Receiving the Uploaded File
68
57
69
58
The `MediaObject` resource is implemented like this:
@@ -98,9 +87,6 @@ use Vich\UploaderBundle\Mapping\Annotation as Vich;
Note: From V3.3 onwards, `'multipart/form-data'` must either be including in the global API-Platform config, either in `formats` or `defaults->inputFormats`, or defined as an `inputFormats` parameter on an operation by operation basis.
147
134
148
-
### Creating the Processor
149
-
150
-
At this point, the entity is configured, but we still need to write the processor
151
-
that handles the file upload.
152
-
153
-
```php
154
-
<?php
155
-
// api/src/State/SaveMediaObject.php
156
-
157
-
namespace App\State;
158
-
159
-
use ApiPlatform\Metadata\Operation;
160
-
use ApiPlatform\State\ProcessorInterface;
161
-
use App\Entity\MediaObject;
162
-
use Symfony\Component\DependencyInjection\Attribute\Autowire;
163
-
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
164
-
use Vich\UploaderBundle\Storage\StorageInterface;
165
-
166
-
final class SaveMediaObject implements ProcessorInterface
0 commit comments