This module provides MinIO integration for file storage in Medusa. It implements the file provider interface to handle file uploads, downloads, and deletions using MinIO as the storage backend.
The module requires the following environment variables:
MINIO_ENDPOINT=your-minio-endpoint
MINIO_ACCESS_KEY=your-access-key
MINIO_SECRET_KEY=your-secret-key
MINIO_BUCKET=your-bucket-name # Optional, defaults to 'medusa-media'
- Automatic bucket creation and configuration
- Default bucket name 'medusa-media' (can be overridden if needed)
- Automatic bucket policy configuration for public read access
- Unique file naming using ULID
- Proper content type and metadata handling
- Presigned URLs for secure file access
- Fallback to local storage if MinIO is not configured
The module is automatically configured in medusa-config.js when the required environment variables are present:
{
resolve: './src/modules/minio-file',
options: {
endPoint: MINIO_ENDPOINT,
accessKey: MINIO_ACCESS_KEY,
secretKey: MINIO_SECRET_KEY,
bucket: MINIO_BUCKET // Optional, defaults to 'medusa-media'
}
}
When changing configuration (especially the bucket name):
- Stop the Medusa server
- Delete the
.medusa/server
directory to clear cached configuration - Restart the server
This is necessary because Medusa caches environment variables in the .medusa/server
directory.
When the service starts:
- It checks for the existence of the configured bucket (default: 'medusa-media')
- Creates the bucket if it doesn't exist
- Configures or updates the bucket policy for public read access
- Logs all initialization steps for transparency
This happens only once when the service starts, not on every file operation.
Files are automatically uploaded to MinIO when using Medusa's file upload endpoints or services. Each file is stored with:
- A unique name generated using ULID
- The original file extension preserved
- Proper content type set
- Original filename stored in metadata
- Public read access enabled
Files can be accessed in two ways:
- Direct URL:
https://${MINIO_ENDPOINT}/${BUCKET_NAME}/${fileKey}
- Files are publicly accessible due to bucket policy configuration
- Presigned URL: Generated on demand with 24-hour expiration
- Useful for temporary access to files
Files are automatically deleted from MinIO when using Medusa's file deletion endpoints or services.
- Port 443 and SSL are hardcoded as this is standard for production MinIO instances
- Files are given unique names using ULID to prevent collisions
- Original filenames are preserved in metadata
- Non-existent file deletions are logged but don't throw errors
- Presigned URLs are valid for 24 hours
- Bucket policy is automatically configured for public read access
- Files are uploaded with 'public-read' ACL
The module configures the MinIO bucket for public read access, which means:
- All uploaded files will be publicly accessible via their URLs
- This is suitable for public assets like product images
- For private files, consider using presigned URLs instead of direct access
If you're migrating from another storage solution or have an existing bucket:
- Set the MINIO_BUCKET environment variable to your existing bucket name
- Delete the
.medusa/server
directory to clear cached configuration - Restart the server
- The module will use your existing bucket and ensure it has the correct public read policy
-
Files uploading to wrong bucket:
- Delete the
.medusa/server
directory to clear cached configuration - Restart the server
- The correct bucket configuration will be used
- Delete the
-
Bucket policy issues:
- The service attempts to set/update the bucket policy on startup
- Check the logs for any policy-related errors
- Ensure your MinIO credentials have sufficient permissions
This module is based on the official Medusa file provider interface. For more information, see: