S3 File Module Provider
The S3 File Module Provider integrates Amazon S3 and services following a compatible API (such as MinIO or DigitalOcean Spaces) to store files uploaded to your Medusa application.
Prerequisites#
- AWS account.
- Create AWS user with AmazonS3FullAccess permissions.
- Create AWS user access key ID and secret access key.
- Create S3 bucket with the "Public Access setting" enabled:
- On your bucket's dashboard, click on the Permissions tab.
- Click on the Edit button of the Block public access (bucket settings) section.
- In the form that opens, don't toggle any checkboxes and click the "Save changes" button.
- Confirm saving the changes by entering
confirmin the pop-up that shows. - Back on the Permissions page, scroll to the Object Ownership section and click the Edit button.
- In the form that opens:
- Choose the "ACLs enabled" card.
- Click on the "Save changes" button.
- Back on the Permissions page, scroll to the "Access Control List (ACL)" section and click on the Edit button.
- In the form that opens, enable the Read permission for "Everyone (public access)".
- Check the "I understand the effects of these changes on my objects and buckets." checkbox.
- Click on the "Save changes" button.
Register the S3 File Module#
Add the module into the providers array of the File Module:
import { Modules } from "@medusajs/framework/utils"
// ...
module.exports = {
// ...
modules: [
// ...
{
resolve: "@medusajs/medusa/file",
options: {
providers: [
{
resolve: "@medusajs/medusa/file-s3",
id: "s3",
options: {
file_url: process.env.S3_FILE_URL,
access_key_id: process.env.S3_ACCESS_KEY_ID,
secret_access_key: process.env.S3_SECRET_ACCESS_KEY,
region: process.env.S3_REGION,
bucket: process.env.S3_BUCKET,
endpoint: process.env.S3_ENDPOINT,
// other options...
},
},
],
},
},
],
}
Additional Configuration for MinIO and Supabase#
If you're using MinIO or Supabase, set to in the object.
For example:
module.exports = defineConfig({
// ...
modules: [
{
resolve: "@medusajs/medusa/file",
options: {
providers: [
{
resolve: "@medusajs/medusa/file-s3",
id: "s3",
options: {
// ...
additional_client_config: {
forcePathStyle: true,
},
},
},
],
},
},
],
})
S3 File Module Options#
Option | Description | Default |
|---|---|---|
| The base URL to upload files to.
| - |
| The AWS or (S3 compatible) user's access key ID. | - |
| The AWS or (S3 compatible) user's secret access key. | - |
| The bucket's region code. For MinIO, use For Cloudflare, use | - |
| The bucket's name. | - |
| The URL to the AWS S3 (or compatible S3 API) server.
| - |
| A string to prefix each uploaded file's name. | - |
| A string indicating how long objects remain in the AWS S3 (or compatible S3 API) cache. |
|
| A number indicating the expiry time of presigned URLs in seconds. |
|
| Any additional configurations to pass to the S3 client. Refer to this AWS API reference for a full list of accepted configuration. | - |