Odoo Attachments to Cloudflare R2 with fs_storage
Odoo deployments on stateless platforms like Google Cloud Run can lead to issues with lost attachments and frontend assets. This article details a solution using Cloudflare R2 and the fs_storage module to ensure persistent storage for Odoo.

The Problem of Stateless Odoo Deployments
Deploying Odoo on stateless platforms, such as Google Cloud Run, presents a significant challenge regarding file persistence. When Odoo instances spin up and down, any files stored within the container's ephemeral filesystem, including essential assets like CSS and JavaScript for the web editor, can be lost. This leads to a broken user interface, often manifesting as a white screen with 404 errors in the browser console for static assets.
The core issue arises from Odoo's reliance on its filestore for various types of data. While sessions can sometimes be redirected to external stores like Redis or PostgreSQL, the direct attachment storage for frontend assets and user uploads requires a more robust solution. Simply rerunning Odoo's asset regeneration commands doesn't solve the underlying problem if the storage mechanism itself is volatile. This lack of persistent storage makes stateless environments unsuitable for Odoo without a proper externalized filestore.
Understanding Odoo's Attachment Storage
Odoo, by default, stores attachments, including generated static assets like CSS and JavaScript for the web editor, within its configured filestore. This filestore can be a local filesystem directory or an external object storage solution. When Odoo runs in a stateless containerized environment, the local filesystem is ephemeral. If the container is terminated and a new one starts, any files not persisted externally are lost. This directly impacts the availability of Odoo's interface elements.
The problem is exacerbated because these assets are not just user uploads but also integral parts of Odoo's dynamic functionality. Without them, users might not be able to access or edit content, rendering the application unusable. Solutions attempting to store sessions externally, while helpful for user session data, do not address the fundamental need to persist the actual files Odoo relies upon.
Introducing Cloudflare R2 as an Object Storage Solution
For applications requiring persistent object storage, cloud-native solutions are often employed. While Amazon S3 is a common choice, services like Cloudflare R2 offer a compelling alternative. R2 is designed for S3-compatible access, meaning it can often integrate with tools and libraries that already support S3. This compatibility is crucial for migrating existing Odoo setups or adopting new storage backends without extensive re-engineering.
Cloudflare R2 provides a cost-effective and performant way to store large amounts of unstructured data. By offloading Odoo's attachments to R2, the application becomes less dependent on the ephemeral storage of its hosting environment. This move is particularly beneficial for stateless deployments where containers are frequently created and destroyed, ensuring that critical assets remain accessible regardless of the underlying compute instance.
Leveraging fs_storage for Odoo and R2 Integration
The fs_storage module, also known as odoo-filesystem-storage, is designed to bridge Odoo with external storage solutions, including S3-compatible object storage like Cloudflare R2. This module allows Odoo to treat object storage buckets as its filestore. By configuring fs_storage with the appropriate credentials and endpoint for Cloudflare R2, Odoo attachments can be seamlessly stored and retrieved from R2.
Configuration involves setting specific Odoo parameters, typically via the Odoo configuration file or environment variables. These parameters include the R2 access key, secret key, bucket name, and the R2 endpoint URL. Once configured, Odoo will automatically upload new attachments to the specified R2 bucket and serve existing ones directly from there, effectively decoupling file storage from the Odoo application's runtime environment.
Implementation Steps and Configuration
To move Odoo attachments to Cloudflare R2 using fs_storage, begin by setting up a bucket in your Cloudflare account. Note down the bucket name, your R2 API access key ID, and your R2 API secret access key. You will also need the R2 endpoint URL, which is typically in the format <account-hash>.r2.cloudflarestorage.com.
Next, install the fs_storage module in your Odoo instance. This often involves adding it to your Odoo add-ons path and upgrading the database. Then, configure Odoo's system parameters. Key parameters include:
fs_storage.storage_type: Set tos3.fs_storage.aws_access_key_id: Your R2 access key ID.fs_storage.aws_secret_access_key: Your R2 secret access key.fs_storage.aws_bucket_name: The name of your Cloudflare R2 bucket.fs_storage.aws_endpoint: The R2 endpoint URL.
After configuration, it is often necessary to trigger a migration of existing attachments. This can be done through Odoo's interface or via custom scripts to move files from the local filestore to R2. Testing thoroughly is essential to ensure all attachments are accessible and new uploads are correctly stored.
Where This Approach Does Not Fit
While using fs_storage with Cloudflare R2 is a robust solution for persistent storage, it may not be the ideal fit for all Odoo deployments. This approach is primarily designed to overcome the challenges of stateless hosting environments by externalizing file storage. If you are running Odoo on a traditional VM or a stateful Kubernetes persistent volume setup, the need for an external object store for core attachments might be less critical, though still beneficial for scalability and disaster recovery.
Furthermore, the complexity of configuring and managing object storage credentials and permissions adds an operational overhead. For very small, single-user instances or simple internal tools where data loss is not a critical concern and stateless deployment is not a requirement, the added complexity might outweigh the benefits. It's crucial to weigh the cost of R2 storage and the management effort against the benefits of improved reliability and scalability for your specific use case.
- #odoo attachment storage
- #odoo cloudflare r2
- #odoo fs_storage
- #odoo s3 attachments
- #odoo stateless deployment

Comments