Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion docusaurus/docs/cms/api/rest/upload.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ The [Media Library feature](/cms/features/media-library) is powered in the back-

Upload one or more files to your application.

`files` is the only accepted parameter, and describes the file(s) to upload. The value(s) can be a Buffer or Stream:
`files` is the only accepted parameter, and describes the file(s) to upload. The value(s) can be a Buffer or Stream.

:::tip
When uploading an image, include a `fileInfo` object to set the file name, alt text, and caption.
:::

<Tabs>
<TabItem value="browser" label="Browser">
Expand All @@ -39,6 +43,12 @@ Upload one or more files to your application.
<form>
<!-- Can be multiple files -->
<input type="file" name="files" />
<input
type="hidden"
name="fileInfo"
value='{"name":"homepage-hero","alternativeText":"Person smiling while
holding laptop","caption":"Hero image used on the homepage"}'
/>
<input type="submit" value="Submit" />
</form>

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

form.append('files', file, "1.png");
form.append(
'fileInfo',
JSON.stringify({
name: 'Homepage hero',
alternativeText: 'Person smiling while holding laptop',
caption: 'Hero image used on the homepage',
})
);

const response = await fetch('http://localhost:1337/api/upload', {
method: 'post',
Expand Down
4 changes: 4 additions & 0 deletions docusaurus/docs/cms/features/media-library.md
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,10 @@ Breakpoint changes will only apply to new images, existing images will not be re

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

:::info
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).
:::

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.

Assets uploaded to the Media Library can be inserted into content-types using the [Content Manager](/cms/features/content-manager#creating--writing-content).
Expand Down
16 changes: 15 additions & 1 deletion docusaurus/static/llms-code.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10693,7 +10693,7 @@ File path: N/A
Source: https://docs.strapi.io/cms/api/rest/upload

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

Language: HTML
Expand All @@ -10703,6 +10703,12 @@ File path: N/A
<form>
<!-- Can be multiple files -->
<input type="file" name="files" />
<input
type="hidden"
name="fileInfo"
value='{"name":"homepage-hero","alternativeText":"Person smiling while
holding laptop","caption":"Hero image used on the homepage"}'
/>
<input type="submit" value="Submit" />
</form>

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

form.append('files', file, "1.png");
form.append(
'fileInfo',
JSON.stringify({
name: 'Homepage hero',
alternativeText: 'Person smiling while holding laptop',
caption: 'Hero image used on the homepage',
})
);

const response = await fetch('http://localhost:1337/api/upload', {
method: 'post',
Expand Down
6 changes: 5 additions & 1 deletion docusaurus/static/llms-full.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4495,7 +4495,11 @@ The [Media Library feature](/cms/features/media-library) is powered in the back-

Upload one or more files to your application.

`files` is the only accepted parameter, and describes the file(s) to upload. The value(s) can be a Buffer or Stream:
`files` is the only accepted parameter, and describes the file(s) to upload. The value(s) can be a Buffer or Stream.

:::tip
When uploading an image, include a `fileInfo` object to set the file name, alt text, and caption.
:::

</Tabs>

Expand Down