Skip to content

Commit fce0056

Browse files
authored
docs: add a file upload section to admin (#1227)
1 parent 2a74066 commit fce0056

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

admin/file-upload.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Handling File Upload
2+
3+
If you need to handle the file upload in the server part, please follow [the related documentation](../core/file-upload.md).
4+
5+
This documentation assumes you have a `/media_objects` endpoint accepting `multipart/form-data`-encoded data.
6+
7+
To manage the upload in the admin part, you need to customize [the create form](customizing.md#customizing-the-create-form) or [the edit form](customizing.md#customizing-the-edit-form).
8+
9+
Add a [FileInput](https://marmelab.com/react-admin/Inputs.html#fileinput) as a child of the guesser. For example, for the create form:
10+
11+
```js
12+
import {
13+
HydraAdmin,
14+
ResourceGuesser,
15+
CreateGuesser,
16+
InputGuesser
17+
} from "@api-platform/admin";
18+
import { FileField, FileInput } from "react-admin";
19+
20+
const MediaObjectsCreate = props => (
21+
<CreateGuesser {...props}>
22+
<FileInput source="file">
23+
<FileField source="src" title="title" />
24+
</FileInput>
25+
</CreateGuesser>
26+
);
27+
28+
export default () => (
29+
<HydraAdmin entrypoint="https://demo.api-platform.com">
30+
<ResourceGuesser name="media_objects" create={MediaObjectsCreate} />
31+
{/* ... */}
32+
</HydraAdmin>
33+
);
34+
```
35+
36+
And that's it!
37+
You don't need to decorate the data provider if you are using the Hydra one: it detects that you have used a `FileInput` and uses a `multipart/form-data` request instead of a JSON-LD one.

outline.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ chapters:
6464
- handling-relations
6565
- schema.org
6666
- authentication-support
67+
- file-upload
6768
- performance
6869
- customizing
6970
- components

0 commit comments

Comments
 (0)