Skip to content

Commit bc5a094

Browse files
author
maxime delemarle
committed
fix: patch indentation for mutiples markdown Files. Change documentation for file upload to indicate well the way to use ApiPlatform with VIchUploaderBundle
1 parent f3702bd commit bc5a094

File tree

5 files changed

+45
-11
lines changed

5 files changed

+45
-11
lines changed

Diff for: core/content-negotiation.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ merge new encoders and normalizers in API Platform.
356356
## JSON:API sparse fieldset and sort parameters
357357

358358
> [!WARNING]
359-
> The SortFilter is for Eloquent, the Doctrine equivalent is the OrderFilter.
359+
> The SortFilter is for Eloquent, the Doctrine equivalent is the OrderFilter.
360360
> The config/api-platform.php is Laravel specific.
361361

362362
When working with JSON:API you may want to declare the `SparseFieldset` and the
@@ -371,11 +371,11 @@ use ApiPlatform\JsonApi\Filter\SparseFieldset;
371371
use ApiPlatform\Laravel\Eloquent\Filter\JsonApi\SortFilter;
372372
373373
return [
374-
// ...
375-
'parameters' => [
376-
new QueryParameter(key: 'fields', filter: SparseFieldset::class),
377-
new QueryParameter(key: 'sort', filter: SortFilter::class),
378-
],
374+
// ...
375+
'parameters' => [
376+
new QueryParameter(key: 'fields', filter: SparseFieldset::class),
377+
new QueryParameter(key: 'sort', filter: SortFilter::class),
378+
],
379379
];
380380
```
381381

Diff for: core/elasticsearch.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ application search, security analytics, metrics, logging, etc.
88
API Platform comes natively with the **reading** support for Elasticsearch. It uses internally the official PHP client
99
for Elasticsearch: [Elasticsearch-PHP](https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/index.html).
1010

11-
Be careful, API Platform only supports Elasticsearch >= 7.11.0 < 8.0 and Elasticsearch >= 8.4 < 9.0. Support for
11+
Be careful, API Platform only supports Elasticsearch >= 7.11.0 < 8.0 and Elasticsearch >= 8.4 < 9.0. Support for
1212
Elasticsearch 8 was introduced in API Platform 3.2.
1313

1414
## Enabling Reading Support

Diff for: core/errors.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ Since 3.4, you also have the possibility to link your specific domain exceptions
330330
directly in your OpenAPI definition !
331331

332332
Let's say that you have a `Greetings` resource, and that one of its providers can throw the following exception for the
333-
`ApiPlatform\Metadata\GetCollection` Operation:
333+
`ApiPlatform\Metadata\GetCollection` Operation:
334334

335335
```php
336336
use ApiPlatform\Metadata\ErrorResource;
@@ -369,7 +369,7 @@ class MyDomainException extends \Exception implements ProblemExceptionInterface
369369
```
370370

371371
As long as your Exception implements `ApiPlatform\Metadata\Exception\ProblemExceptionInterface` and has the `ErrorResource`
372-
attribute, you can then map it to your Operation this way:
372+
attribute, you can then map it to your Operation this way:
373373

374374
```php
375375
use ApiPlatform\Metadata\ApiResource;

Diff for: extra/releases.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ For example:
1010
- version 3.2 has been released on 12 October 2023;
1111
- version 3.3 has been released on 9 April 2024 (we were a little late, it should have been published in March);
1212
- versions 3.4 has been released on 18 September 2024;
13-
- versions 4.0 has been released on 27 September 2024;
14-
- versions 4.1 has been released on 28 February 2025;
13+
- versions 4.0 has been released on 27 September 2024;
14+
- versions 4.1 has been released on 28 February 2025;
1515

1616
## Maintenance
1717

Diff for: symfony/file-upload.md

+34
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ use Vich\UploaderBundle\Mapping\Annotation as Vich;
8484
new GetCollection(),
8585
new Post(
8686
inputFormats: ['multipart' => ['multipart/form-data']],
87+
controller: CreateMediaObjectAction::class,
88+
deserialize: false,
8789
openapi: new Model\Operation(
8890
requestBody: new Model\RequestBody(
8991
content: new \ArrayObject([
@@ -130,6 +132,38 @@ class MediaObject
130132

131133
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.
132134

135+
### Creating the Controller
136+
At this point, the entity is configured, but we still need to write the action that handles the file upload.
137+
```php
138+
<?php
139+
// api/src/Controller/CreateMediaObjectAction.php
140+
141+
namespace App\Controller;
142+
143+
use App\Entity\MediaObject;
144+
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
145+
use Symfony\Component\HttpFoundation\Request;
146+
use Symfony\Component\HttpKernel\Attribute\AsController;
147+
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
148+
149+
#[AsController]
150+
final class CreateMediaObjectAction extends AbstractController
151+
{
152+
public function __invoke(Request $request): MediaObject
153+
{
154+
$uploadedFile = $request->files->get('file');
155+
if (!$uploadedFile) {
156+
throw new BadRequestHttpException('"file" is required');
157+
}
158+
159+
$mediaObject = new MediaObject();
160+
$mediaObject->file = $uploadedFile;
161+
162+
return $mediaObject;
163+
}
164+
}
165+
```
166+
133167
### Resolving the File URL
134168

135169
Returning the plain file path on the filesystem where the file is stored is not useful for the client, which needs a

0 commit comments

Comments
 (0)