Assets
Spree uses Active Storage to handle file uploads (eg. product images). By default, Active Storage uses local disk storage for attachments. This isn’t suitable for production environments.
For production environments, we recommend using a cloud storage service such as AWS S3 or Cloudflare R2.
AWS S3
To use Amazon S3 as your storage service, you need to configure the storage in the config/storage.yml
file.
You will also need to add the aws-sdk-s3
gem to your Gemfile.
And run bundle install
.
Now you need to switch the storage service in your config/environments/production.rb
file.
Now you will need to grab the credentials from your AWS S3 bucket and add them to rails credentials by running the following command:
Add the following credentials:
Save and exit the editor. Remember to commit the changes to your repository.
CORS Configuration
Spree Admin Dashboard uses direct uploads to handle file uploads. For this to work properly, you need to configure CORS on your S3 bucket.
- Go to your S3 bucket in AWS Console
- Click on “Permissions” tab
- Scroll down to “Cross-origin resource sharing (CORS)”
- Click “Edit” and paste the following configuration:
myspreestore.com
should be replaced with your domain name which you access your Spree Admin Dashboard.
Cloudflare R2
Cloudflare R2 is an S3-compatible, zero egress-fee, object storage with a built-in CDN. We strongly recommend using it as your storage service.
To use Cloudflare R2 as your storage service, you need to configure the storage in the config/storage.yml
file.
You will also need to add the aws-sdk-s3
gem to your Gemfile.
And run bundle install
.
Now you need to switch the storage service in your config/environments/production.rb
file.
Now you will need to grab the credentials from your Cloudflare R2 bucket and add them to rails credentials by running the following command:
Add the following credentials:
Save and exit the editor. Remember to commit the changes to your repository.
CORS Configuration
Spree Admin Dashboard uses direct uploads to handle file uploads. For this to work properly, you need to configure CORS on your R2 bucket.
- Go to your R2 bucket in Cloudflare Console
- Click on “Settings” tab
- Scroll down to “CORS policy”
- Click “Edit CORS policy” and paste the following configuration:
myspreestore.com
should be replaced with your domain name which you access your Spree Admin Dashboard.
Was this page helpful?