Skip to content

Commit 19b4ec2

Browse files
authored
docs: use local API to upload a local file (#10839)
1 parent bef98c8 commit 19b4ec2

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

docs/upload/overview.mdx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,32 @@ fetch('api/:upload-slug', {
347347
})
348348
```
349349

350+
## Uploading Files stored locally
351+
352+
If you want to upload a file stored on your machine directly using the `payload.create` method, for example, during a seed script,
353+
you can use the `filePath` property to specify the local path of the file.
354+
355+
```ts
356+
const localFilePath = path.resolve(__dirname, filename)
357+
358+
await payload.create({
359+
collection: 'media',
360+
data: {
361+
alt,
362+
},
363+
filePath: localFilePath,
364+
})
365+
```
366+
367+
The `data` property should still include all the required fields of your `media` collection.
368+
369+
<Banner type="warning">
370+
**Important:**
371+
372+
Remember that all custom hooks attached to the `media` collection will still trigger.
373+
Ensure that files match the specified mimeTypes or sizes defined in the collection's `formatOptions` or custom `hooks`.
374+
</Banner>
375+
350376
## Uploading Files from Remote URLs
351377

352378
The `pasteURL` option allows users to fetch files from remote URLs by pasting them into an Upload field. This option is **enabled by default** and can be configured to either **allow unrestricted client-side fetching** or **restrict server-side fetching** to specific trusted domains.

0 commit comments

Comments
 (0)