{"id":3521,"date":"2018-06-07T12:16:22","date_gmt":"2018-06-07T12:16:22","guid":{"rendered":"https:\/\/www.botreetechnologies.com\/blog\/?p=3521"},"modified":"2026-04-02T11:04:52","modified_gmt":"2026-04-02T05:34:52","slug":"rails-5-2-upload-files-to-s3-with-active-storage-rails-5-2-credentials","status":"publish","type":"post","link":"https:\/\/www.botreetechnologies.com\/blog\/rails-5-2-upload-files-to-s3-with-active-storage-rails-5-2-credentials\/","title":{"rendered":"Upload files to Amazon S3 using Active Storage with Securely Storing Credentials"},"content":{"rendered":"\n<p>File uploading feature is very common demand of any application, there are several options available in rails to incorporate this feature in an application such as Paperclip, Carrierwave, Refile etc. These are few gems that can be used to implement File Upload.<\/p>\n\n\n\n<p>Rails 5.2 comes up with the inbuilt feature called Active Storage for the same purpose i.e File uploading which is much simpler than existing options.<\/p>\n\n\n\n<p>Let&#8217;s see what makes it simple and reliable.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What actually Active Storage is?<\/h2>\n\n\n\n<p><a href=\"https:\/\/www.botreetechnologies.com\/blog\/change-default-file-path-of-active-storage-in-ruby-on-rails-5\">Active Storage<\/a> provides file uploading (supports all file types) facility to cloud storage like Amazon S3, Google Cloud and Microsoft Azure Storage. It provides disk-based service for development and testing environment. With the help of Active Storage, an application can transform image uploads with ImageMagic, generate image representations of non-image uploads like PDFs and videos, and extract meta-data from arbitrary files.<\/p>\n\n\n\n<p>Let&#8217;s start our setup for Active Storage for uploading files to Amazon S3. Here we will assume that we have our existing rails 5.2 application in which we wish to implement a file upload feature. Here we go!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Active Storage Setup<\/h2>\n\n\n\n<p>Active Storage uses two tables in the application&#8217;s database named <i>active_storage_blobs<\/i> and <i>active_storage_attachments<\/i>. So first we need to generate these two tables in our application&#8217;s database with the following commands:<\/p>\n\n\n\n<p>Generate a migration that creates these table and runs the migration<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><code>rails active_storage:install<br>\nrails db:migrate<\/code><\/p><\/blockquote>\n\n\n\n<p>Now we will declare Active Storage services in <i>config\/storage.yml<\/i>. For each service our application uses, we will provide a name and the requisite configuration. Following example declares three services named <i>local<\/i>, <i>test<\/i>, and <i>Amazon<\/i>.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><code>local:<br>\nservice: Disk<br>\nroot: &lt;%= Rails.root.join(\"storage\") %&gt;<br>\ntest:<br>\nservice: Disk<br>\nroot: &lt;%= Rails.root.join(\"tmp\/storage\") %&gt;<br>\namazon:<br>\nservice: S3<br>\naccess_key_id: \"52634587467\"<br>\nsecret_access_key: \"hqwjkshwdhewjk\"<br>\n(Bellow we will be seeing how to save aws secrets using Rails 5.2 encrypted credentials, as of now you can keep this simple)<\/code><\/p><\/blockquote>\n\n\n\n<p>You can add any of the supported services by Active Storage (Amazon S3, Google Cloud Storage, or Microsoft Azure Storage) here but as this article is about Amazon S3 we will see Amazon S3 setup further.<\/p>\n\n\n\n<p>Each environment will use a different service, so we need to tell to Active Storage that which service is to be used. So depending upon application&#8217;s environment (Development, Test, Production) we need to add the following line in our environment files. Suppose here we are setting up Active Storage for Production environment so we will add the following to <i>config\/environments\/production.rb<\/i><\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><code># Store files on Amazon S3.<br>\nconfig.active_storage.service = :amazon<\/code><\/p><\/blockquote>\n\n\n\n<p>Now add <i><code>gem \"aws-sdk-s3\", require: false<\/code><\/i> to you Gemfile and run bundle installs.<\/p>\n\n\n\n<p>That&#8217;s it! Here our Active Storage setup is completed.<br>Now we will see how to upload files with active storage.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Attaching files to records<\/h3>\n\n\n\n<p>Active Storage provides two macros <i><code>has_one_attached<\/code><\/i> and <i><code>has_many_attached<\/code><\/i> for defining a relationship between files and models<\/p>\n\n\n\n<p>The <i><code>has_one_attached<\/code><\/i> macro sets up a one-to-one mapping between records and files. Each record can have one file attached to it.<\/p>\n\n\n\n<p>For example, suppose our application has an <b>Employee<\/b> model. We want to have each employee to have one photo, then our Employee model will look like this &#8211;<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><code>class Employee &lt; ApplicationRecord<br>\nhas_one_attached :photoe<br>\nend<\/code><\/p><\/blockquote>\n\n\n\n<p>We can create Employee with a photo like:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><code>class EmployeesController &lt; ApplicationController<br>\ndef create<br>\nemployee = Employee.create!(employee_params)<br>\nredirect_to root_path<br>\nend<br>\nprivate<br>\ndef employee_params<br>\nparams.require(:employee).permit(:first_name, :last_name, :photo)<br>\nend<br>\nend<\/code><\/p><\/blockquote>\n\n\n\n<p>Can attach the photo to an existing employee using:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><code>employee.photo.attach(params[:photo])<\/code><\/p><\/blockquote>\n\n\n\n<p>Can check whether an employee has the photo or not with:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><code>employee.photo.attached?<\/code><\/p><\/blockquote>\n\n\n\n<p>The <i><code>has_many_attached<\/code><\/i> macro sets up a one-to-many mapping between records and files. Each record can have one file attached to it.<\/p>\n\n\n\n<p>For example, suppose our application has a Product model. We want to have each product to have multiple images, then our Product model will look like this &#8211;<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><code>class Message &lt; ApplicationRecord<br>\nhas_many_attached :images<br>\nend<\/code><\/p><\/blockquote>\n\n\n\n<p>We can create Product with images like &#8211;<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><code>class ProductsController &lt; ApplicationController<br>\ndef create<br>\nproducts = Product.create!(product_params)<br>\nredirect_to product<br>\nend<br>\nprivate<br>\ndef product_params<br>\nparams.require(:product).permit(:title, :description, images: [])<br>\nend<br>\nend<\/code><\/p><\/blockquote>\n\n\n\n<p>Can attach images to existing products using:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><code>@product.images.attach(params[:images])<\/code><\/p><\/blockquote>\n\n\n\n<p>Can check whether a product has the image or not with:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><code>@product.images.attached?<\/code><\/p><\/blockquote>\n\n\n\n<h3 class=\"wp-block-heading\">Attaching File\/IO Objects<\/h3>\n\n\n\n<p>There is often a situation that we need to attach some files to records which are not arriving from HTTP request, sometimes we need to attach files which are stored on our system, this also can be achieved using Active Storage. To do that, provide a Hash containing at least an open IO object and a filename &#8211;<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><code>@product.image.attach(<br>\nio: File.open('\/path\/to\/file'),<br>\nfilename: 'file.pdf'<br>\n)<\/code><\/p><\/blockquote>\n\n\n\n<p>If possible try to provide a content type as well. Active Storage attempts to determine a file&#8217;s content type from its data. It falls back to the content type you provide if it can&#8217;t do that &#8211;<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><code>@product.image.attach(<br>\nio: File.open('\/path\/to\/file'),<br>\nfilename: 'file.pdf',<br>\ncontent_type: 'application\/pdf'<br>\n)<\/code><\/p><\/blockquote>\n\n\n\n<p>We can bypass the content type inference from the data by passing in <i>identify: false<\/i> along with the <i>content_type<\/i>.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><code>@product.image.attach(<br>\nio: File.open('\/path\/to\/file'),<br>\nfilename: 'file.pdf',<br>\ncontent_type: 'application\/pdf'<br>\nidentify: false<br>\n)<\/code><\/p><\/blockquote>\n\n\n\n<p>If we don&#8217;t provide a content type and Active Storage can&#8217;t determine the file&#8217;s content type automatically, it defaults to application\/octet-stream.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Removing Attached Files<\/h3>\n\n\n\n<p>We can remove attached files with <i>purge<\/i>:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><code># Synchronously destroy the avatar and actual resource files.<br>\n@employee.photo.purge<br>\n# Destroy the associated models and actual resource files async, via Active Job.<br>\n@employee.photo.purge_later<\/code><\/p><\/blockquote>\n\n\n\n<h3 class=\"wp-block-heading\">Linking to Files<\/h3>\n\n\n\n<p>Generating URL for files.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><code>url_for(@employee.photo)<\/code><\/p><\/blockquote>\n\n\n\n<p>To create a download link, use the <i>rails_blob_{path|url}<\/i> helper. Using this helper allows you to set the disposition.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><code>rails_blob_path(@employee.photo, disposition: \"attachment\")<\/code><\/p><\/blockquote>\n\n\n\n<p>If we need to create a link from outside of controller\/view context (Background jobs, Cronjobs, etc.), you can access the rails_blob_path like this:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><code>Rails.application.routes.url_helpers.rails_blob_path(@employee.photo, only_path: true)<\/code><\/p><\/blockquote>\n\n\n\n<p><b>Downloading Files:<\/b> We can download file with:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><code>pic = @employee.photo.download<\/code><\/p><\/blockquote>\n\n\n\n<p>We might want to download a blob to a file on disk so an external program (e.g. a virus scanner or media transcoder) can operate on it. Use <i><code>ActiveStorage::Blob#open<\/code><\/i> to download a blob to a temp file on disk<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><code>product.images.open do |file|<br>\nsystem '\/path\/to\/virus\/scanner', file.path<br>\n# ...<br>\nend<\/code><\/p><\/blockquote>\n\n\n\n<p>That&#8217;s it! Here we have seen all basics related to Active Storage. Isn&#8217;t it pretty simple?<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">How to store credentials using a master key in Rails 5.2?<\/h3>\n\n\n\n<p>Rails 5.2 have replaced both secrets provided by Rails 5.1, with encrypted credentials. We cannot use plain text credentials. There&#8217;s only credentials.yml.enc.<\/p>\n\n\n\n<p>To use encrypted credentials, we need a key. Without this encryption key, we won&#8217;t be able to decrypt our credentials. We can commit the encrypted file to our repository but we should avoid committing the encryption key.<\/p>\n\n\n\n<p>When we fire command rails new, one file gets generated config\/master.key. The encryption key for our application gets generated and get stored in this file.<\/p>\n\n\n\n<p>The encrypted credentials are saved on config\/credentials.yml.enc. Don&#8217;t edit the file directly. To add credentials, run<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><code>bin\/rails credentials:edit<\/code><\/p><\/blockquote>\n\n\n\n<p>If you do not have any editor set, use the following:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><code>EDITOR=nano bin\/rails credentials:edit<br>\n(I prefer to use nano, you can set it your favorite one)<\/code><\/p><\/blockquote>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1000\" height=\"552\" src=\"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/12\/credentials-yml.png\" alt=\"credentials yml\" class=\"wp-image-13615\" srcset=\"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/12\/credentials-yml.png 1000w, https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/12\/credentials-yml-300x166.png 300w, https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/12\/credentials-yml-768x424.png 768w\" sizes=\"auto, (max-width: 1000px) 100vw, 1000px\" \/><\/figure><\/div>\n\n\n\n<p>credentials.yml.enc will get opened enter your AWS secrets here <\/p>\n\n\n\n<p>After saving the file, the encrypted version will be saved to <i>config\/credentials.yml.enc<\/i>.<\/p>\n\n\n\n<p>Reading Credentials -For using the credentials in the production environment, add the following to <i>config\/environments\/production.rb<\/i><\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><code>config.require_master_key = true<\/code><\/p><\/blockquote>\n\n\n\n<p>Similarly we can add this for Test and Development environments.<br>Now we can access the credentials with Rails.application.credentials. For example, if we have<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><code>amazon:<br>\nservice: S3<br>\naccess_key_id: \"52634587467\"<br>\nsecret_access_key: \"hqwjkshwdhewjk\"<\/code><\/p><\/blockquote>\n\n\n\n<p>We can access access_key_id, secret_access_key with &#8211;<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><code>Rails.application.credentials.dig(:aws, :access_key_id)<br>\nRails.application.credentials.dig(:aws, :secret_access_key)<\/code><\/p><\/blockquote>\n\n\n\n<p>That&#8217;s it, you are now all set to rock!<\/p>\n\n\n\n<p><strong><a href=\"https:\/\/www.botreetechnologies.com\/ruby-on-rails-development\">Click here for more details<\/a>&#8230;<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>At <a href=\"https:\/\/www.botreetechnologies.com\/\">BoTree Technologies<\/a>, we build enterprise applications with our RoR team of 25+ engineers.<\/p>\n\n\n\n<p>We also specialize in RPA, AI, Python, Django, JavaScript and ReactJS.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><a href=\"https:\/\/www.botreetechnologies.com\/contact\">Consulting is free<\/a> &#8211; let us help you grow!<\/h3>\n","protected":false},"excerpt":{"rendered":"<p>File uploading feature is very common demand of any application,&#8230;<\/p>\n","protected":false},"author":23,"featured_media":13614,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[73,10],"tags":[],"class_list":["post-3521","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ruby-on-rails","category-technology"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.2 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Upload files to Amazon S3 using Active Storage with Securely Storing Credentials<\/title>\n<meta name=\"description\" content=\"Rails 5.2 comes up with inbuilt feature called Active Storage for the same purpose i.e File uploading which is much simpler than existing options.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.botreetechnologies.com\/blog\/rails-5-2-upload-files-to-s3-with-active-storage-rails-5-2-credentials\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Upload files to Amazon S3 using Active Storage with Securely Storing Credentials\" \/>\n<meta property=\"og:description\" content=\"Rails 5.2 comes up with inbuilt feature called Active Storage for the same purpose i.e File uploading which is much simpler than existing options.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.botreetechnologies.com\/blog\/rails-5-2-upload-files-to-s3-with-active-storage-rails-5-2-credentials\/\" \/>\n<meta property=\"og:site_name\" content=\"BoTree Technologies\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/BoTreeTechnologies\/\" \/>\n<meta property=\"article:published_time\" content=\"2018-06-07T12:16:22+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-04-02T05:34:52+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2018\/06\/active-storage-rails.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1024\" \/>\n\t<meta property=\"og:image:height\" content=\"683\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Tejaswini Patil\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@BoTreeTech\" \/>\n<meta name=\"twitter:site\" content=\"@BoTreeTech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Tejaswini Patil\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/rails-5-2-upload-files-to-s3-with-active-storage-rails-5-2-credentials\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/rails-5-2-upload-files-to-s3-with-active-storage-rails-5-2-credentials\/\"},\"author\":{\"name\":\"Tejaswini Patil\",\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/#\/schema\/person\/1a3ecba0676a15b503dfc2dab4f8821f\"},\"headline\":\"Upload files to Amazon S3 using Active Storage with Securely Storing Credentials\",\"datePublished\":\"2018-06-07T12:16:22+00:00\",\"dateModified\":\"2026-04-02T05:34:52+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/rails-5-2-upload-files-to-s3-with-active-storage-rails-5-2-credentials\/\"},\"wordCount\":1107,\"commentCount\":0,\"image\":{\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/rails-5-2-upload-files-to-s3-with-active-storage-rails-5-2-credentials\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2018\/06\/active-storage-rails.jpg\",\"articleSection\":[\"Ruby on Rails\",\"Technology\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.botreetechnologies.com\/blog\/rails-5-2-upload-files-to-s3-with-active-storage-rails-5-2-credentials\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/rails-5-2-upload-files-to-s3-with-active-storage-rails-5-2-credentials\/\",\"url\":\"https:\/\/www.botreetechnologies.com\/blog\/rails-5-2-upload-files-to-s3-with-active-storage-rails-5-2-credentials\/\",\"name\":\"Upload files to Amazon S3 using Active Storage with Securely Storing Credentials\",\"isPartOf\":{\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/rails-5-2-upload-files-to-s3-with-active-storage-rails-5-2-credentials\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/rails-5-2-upload-files-to-s3-with-active-storage-rails-5-2-credentials\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2018\/06\/active-storage-rails.jpg\",\"datePublished\":\"2018-06-07T12:16:22+00:00\",\"dateModified\":\"2026-04-02T05:34:52+00:00\",\"author\":{\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/#\/schema\/person\/1a3ecba0676a15b503dfc2dab4f8821f\"},\"description\":\"Rails 5.2 comes up with inbuilt feature called Active Storage for the same purpose i.e File uploading which is much simpler than existing options.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/rails-5-2-upload-files-to-s3-with-active-storage-rails-5-2-credentials\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.botreetechnologies.com\/blog\/rails-5-2-upload-files-to-s3-with-active-storage-rails-5-2-credentials\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/rails-5-2-upload-files-to-s3-with-active-storage-rails-5-2-credentials\/#primaryimage\",\"url\":\"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2018\/06\/active-storage-rails.jpg\",\"contentUrl\":\"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2018\/06\/active-storage-rails.jpg\",\"width\":1024,\"height\":683,\"caption\":\"Upload files to Amazon S3 using Active Storage\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/rails-5-2-upload-files-to-s3-with-active-storage-rails-5-2-credentials\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.botreetechnologies.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Upload files to Amazon S3 using Active Storage with Securely Storing Credentials\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/#website\",\"url\":\"https:\/\/www.botreetechnologies.com\/blog\/\",\"name\":\"BoTree Technologies\",\"description\":\"Committed to inspire generation.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.botreetechnologies.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/#\/schema\/person\/1a3ecba0676a15b503dfc2dab4f8821f\",\"name\":\"Tejaswini Patil\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/10\/tejaswini-patil-150x150.png\",\"url\":\"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/10\/tejaswini-patil-150x150.png\",\"contentUrl\":\"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/10\/tejaswini-patil-150x150.png\",\"caption\":\"Tejaswini Patil\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Upload files to Amazon S3 using Active Storage with Securely Storing Credentials","description":"Rails 5.2 comes up with inbuilt feature called Active Storage for the same purpose i.e File uploading which is much simpler than existing options.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.botreetechnologies.com\/blog\/rails-5-2-upload-files-to-s3-with-active-storage-rails-5-2-credentials\/","og_locale":"en_US","og_type":"article","og_title":"Upload files to Amazon S3 using Active Storage with Securely Storing Credentials","og_description":"Rails 5.2 comes up with inbuilt feature called Active Storage for the same purpose i.e File uploading which is much simpler than existing options.","og_url":"https:\/\/www.botreetechnologies.com\/blog\/rails-5-2-upload-files-to-s3-with-active-storage-rails-5-2-credentials\/","og_site_name":"BoTree Technologies","article_publisher":"https:\/\/www.facebook.com\/BoTreeTechnologies\/","article_published_time":"2018-06-07T12:16:22+00:00","article_modified_time":"2026-04-02T05:34:52+00:00","og_image":[{"width":1024,"height":683,"url":"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2018\/06\/active-storage-rails.jpg","type":"image\/jpeg"}],"author":"Tejaswini Patil","twitter_card":"summary_large_image","twitter_creator":"@BoTreeTech","twitter_site":"@BoTreeTech","twitter_misc":{"Written by":"Tejaswini Patil","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.botreetechnologies.com\/blog\/rails-5-2-upload-files-to-s3-with-active-storage-rails-5-2-credentials\/#article","isPartOf":{"@id":"https:\/\/www.botreetechnologies.com\/blog\/rails-5-2-upload-files-to-s3-with-active-storage-rails-5-2-credentials\/"},"author":{"name":"Tejaswini Patil","@id":"https:\/\/www.botreetechnologies.com\/blog\/#\/schema\/person\/1a3ecba0676a15b503dfc2dab4f8821f"},"headline":"Upload files to Amazon S3 using Active Storage with Securely Storing Credentials","datePublished":"2018-06-07T12:16:22+00:00","dateModified":"2026-04-02T05:34:52+00:00","mainEntityOfPage":{"@id":"https:\/\/www.botreetechnologies.com\/blog\/rails-5-2-upload-files-to-s3-with-active-storage-rails-5-2-credentials\/"},"wordCount":1107,"commentCount":0,"image":{"@id":"https:\/\/www.botreetechnologies.com\/blog\/rails-5-2-upload-files-to-s3-with-active-storage-rails-5-2-credentials\/#primaryimage"},"thumbnailUrl":"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2018\/06\/active-storage-rails.jpg","articleSection":["Ruby on Rails","Technology"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.botreetechnologies.com\/blog\/rails-5-2-upload-files-to-s3-with-active-storage-rails-5-2-credentials\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.botreetechnologies.com\/blog\/rails-5-2-upload-files-to-s3-with-active-storage-rails-5-2-credentials\/","url":"https:\/\/www.botreetechnologies.com\/blog\/rails-5-2-upload-files-to-s3-with-active-storage-rails-5-2-credentials\/","name":"Upload files to Amazon S3 using Active Storage with Securely Storing Credentials","isPartOf":{"@id":"https:\/\/www.botreetechnologies.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.botreetechnologies.com\/blog\/rails-5-2-upload-files-to-s3-with-active-storage-rails-5-2-credentials\/#primaryimage"},"image":{"@id":"https:\/\/www.botreetechnologies.com\/blog\/rails-5-2-upload-files-to-s3-with-active-storage-rails-5-2-credentials\/#primaryimage"},"thumbnailUrl":"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2018\/06\/active-storage-rails.jpg","datePublished":"2018-06-07T12:16:22+00:00","dateModified":"2026-04-02T05:34:52+00:00","author":{"@id":"https:\/\/www.botreetechnologies.com\/blog\/#\/schema\/person\/1a3ecba0676a15b503dfc2dab4f8821f"},"description":"Rails 5.2 comes up with inbuilt feature called Active Storage for the same purpose i.e File uploading which is much simpler than existing options.","breadcrumb":{"@id":"https:\/\/www.botreetechnologies.com\/blog\/rails-5-2-upload-files-to-s3-with-active-storage-rails-5-2-credentials\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.botreetechnologies.com\/blog\/rails-5-2-upload-files-to-s3-with-active-storage-rails-5-2-credentials\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.botreetechnologies.com\/blog\/rails-5-2-upload-files-to-s3-with-active-storage-rails-5-2-credentials\/#primaryimage","url":"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2018\/06\/active-storage-rails.jpg","contentUrl":"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2018\/06\/active-storage-rails.jpg","width":1024,"height":683,"caption":"Upload files to Amazon S3 using Active Storage"},{"@type":"BreadcrumbList","@id":"https:\/\/www.botreetechnologies.com\/blog\/rails-5-2-upload-files-to-s3-with-active-storage-rails-5-2-credentials\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.botreetechnologies.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Upload files to Amazon S3 using Active Storage with Securely Storing Credentials"}]},{"@type":"WebSite","@id":"https:\/\/www.botreetechnologies.com\/blog\/#website","url":"https:\/\/www.botreetechnologies.com\/blog\/","name":"BoTree Technologies","description":"Committed to inspire generation.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.botreetechnologies.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.botreetechnologies.com\/blog\/#\/schema\/person\/1a3ecba0676a15b503dfc2dab4f8821f","name":"Tejaswini Patil","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/10\/tejaswini-patil-150x150.png","url":"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/10\/tejaswini-patil-150x150.png","contentUrl":"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/10\/tejaswini-patil-150x150.png","caption":"Tejaswini Patil"}}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/3521","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/users\/23"}],"replies":[{"embeddable":true,"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/comments?post=3521"}],"version-history":[{"count":1,"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/3521\/revisions"}],"predecessor-version":[{"id":13616,"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/3521\/revisions\/13616"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/media\/13614"}],"wp:attachment":[{"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/media?parent=3521"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/categories?post=3521"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/tags?post=3521"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}