Skip to content

Overview

Our application uses Rails Active Storage to manage file uploads. Active Storage seamlessly integrates with AWS S3, providing a robust and scalable solution for storing and retrieving files. By leveraging AWS S3, we ensure high availability, durability, and security for our application's file storage needs.

Active Storage abstracts away the complexities of interacting with AWS S3, allowing developers to focus on building features without worrying about the underlying storage infrastructure. It supports various file operations such as uploading, downloading, and processing files, making it a versatile choice for handling file attachments in a Rails application.

Usage in the System

In our system, file management and storage are encapsulated by an application record called Medium. The Medium model is responsible for handling all file-related operations and interactions with Active Storage.

To manage files for any record in the system, a polymorphic relationship with the Medium model is required. This design ensures a consistent and centralized approach to file management across different parts of the application. By using the Medium model, we can easily attach, detach, and manipulate files associated with various records, leveraging the full capabilities of Active Storage and AWS S3.

CloudFront Integration

The frontend of our application uses Medium file references to access and display files. To enhance performance and deliver content efficiently, we use Amazon CloudFront to distribute our AWS S3 bucket. CloudFront is a content delivery network (CDN) that caches and serves files from edge locations around the world, reducing latency and improving load times for users.

Additionally, we utilize Cloudflare Image Optimizer to resize image files on the fly. This allows us to serve appropriately sized images based on the user's device and screen resolution, optimizing bandwidth usage and ensuring a better user experience. By combining CloudFront and Cloudflare Image Optimizer, we achieve a highly performant and scalable solution for delivering media content in our application.

Development Mode

In development mode, we expect developers to either use a disk storage provider or roll out their own S3 bucket. Using a disk storage provider is a simple and convenient option for local development, as it does not require any external dependencies. However, for a more production-like environment, developers can configure their own S3 bucket to test and develop features that rely on cloud storage. This flexibility allows developers to choose the storage solution that best fits their development workflow and requirements.