Skip to content

Commit 1797f92

Browse files
committed
Add details and precisions regarding image uploading
1 parent 64f7011 commit 1797f92

File tree

4 files changed

+43
-3
lines changed

4 files changed

+43
-3
lines changed

docusaurus/docs/cms/api/rest/upload.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ The [Media Library feature](/cms/features/media-library) is powered in the back-
3030

3131
Upload one or more files to your application.
3232

33-
`files` is the only accepted parameter, and describes the file(s) to upload. The value(s) can be a Buffer or Stream:
33+
`files` is the only accepted parameter, and describes the file(s) to upload. The value(s) can be a Buffer or Stream.
34+
35+
:::tip
36+
When uploading an image, include a `fileInfo` object to set the file name, alt text, and caption.
37+
:::
3438

3539
<Tabs>
3640
<TabItem value="browser" label="Browser">
@@ -39,6 +43,12 @@ Upload one or more files to your application.
3943
<form>
4044
<!-- Can be multiple files -->
4145
<input type="file" name="files" />
46+
<input
47+
type="hidden"
48+
name="fileInfo"
49+
value='{"name":"homepage-hero","alternativeText":"Person smiling while
50+
holding laptop","caption":"Hero image used on the homepage"}'
51+
/>
4252
<input type="submit" value="Submit" />
4353
</form>
4454

@@ -68,6 +78,14 @@ const file = await blobFrom('./1.png', 'image/png');
6878
const form = new FormData();
6979

7080
form.append('files', file, "1.png");
81+
form.append(
82+
'fileInfo',
83+
JSON.stringify({
84+
name: 'Homepage hero',
85+
alternativeText: 'Person smiling while holding laptop',
86+
caption: 'Hero image used on the homepage',
87+
})
88+
);
7189

7290
const response = await fetch('http://localhost:1337/api/upload', {
7391
method: 'post',

docusaurus/docs/cms/features/media-library.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,10 @@ Breakpoint changes will only apply to new images, existing images will not be re
489489

490490
**Path to use the feature:** <Icon name="images" /> Media Library
491491

492+
:::info
493+
Strapi supports uploading images from the admin panel or programmatically. From the API, you can send a multipart/form-data request to `/api/upload` with the image file and optional `fileInfo` metadata for captions and alt text (see [REST API documentation](/cms/api/rest/upload#upload-files) for more information).
494+
:::
495+
492496
The Media Library displays all assets uploaded in the application, either via the <Icon name="images" /> Media Library itself or via the <Icon name="feather" /> Content Manager when managing a media field.
493497

494498
Assets uploaded to the Media Library can be inserted into content-types using the [Content Manager](/cms/features/content-manager#creating--writing-content).

docusaurus/static/llms-code.txt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10693,7 +10693,7 @@ File path: N/A
1069310693
Source: https://docs.strapi.io/cms/api/rest/upload
1069410694

1069510695
## Upload files
10696-
Description: files is the only accepted parameter, and describes the file(s) to upload.
10696+
Description: :::tip When uploading an image, include a fileInfo object to set the file name, alt text, and caption.
1069710697
(Source: https://docs.strapi.io/cms/api/rest/upload#upload-files)
1069810698

1069910699
Language: HTML
@@ -10703,6 +10703,12 @@ File path: N/A
1070310703
<form>
1070410704
<!-- Can be multiple files -->
1070510705
<input type="file" name="files" />
10706+
<input
10707+
type="hidden"
10708+
name="fileInfo"
10709+
value='{"name":"homepage-hero","alternativeText":"Person smiling while
10710+
holding laptop","caption":"Hero image used on the homepage"}'
10711+
/>
1070610712
<input type="submit" value="Submit" />
1070710713
</form>
1070810714

@@ -10732,6 +10738,14 @@ const file = await blobFrom('./1.png', 'image/png');
1073210738
const form = new FormData();
1073310739

1073410740
form.append('files', file, "1.png");
10741+
form.append(
10742+
'fileInfo',
10743+
JSON.stringify({
10744+
name: 'Homepage hero',
10745+
alternativeText: 'Person smiling while holding laptop',
10746+
caption: 'Hero image used on the homepage',
10747+
})
10748+
);
1073510749

1073610750
const response = await fetch('http://localhost:1337/api/upload', {
1073710751
method: 'post',

docusaurus/static/llms-full.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4495,7 +4495,11 @@ The [Media Library feature](/cms/features/media-library) is powered in the back-
44954495

44964496
Upload one or more files to your application.
44974497

4498-
`files` is the only accepted parameter, and describes the file(s) to upload. The value(s) can be a Buffer or Stream:
4498+
`files` is the only accepted parameter, and describes the file(s) to upload. The value(s) can be a Buffer or Stream.
4499+
4500+
:::tip
4501+
When uploading an image, include a `fileInfo` object to set the file name, alt text, and caption.
4502+
:::
44994503

45004504
</Tabs>
45014505

0 commit comments

Comments
 (0)