diff --git a/activestorage/.babelrc b/activestorage/.babelrc
new file mode 100644
index 0000000000..a8211d329f
--- /dev/null
+++ b/activestorage/.babelrc
@@ -0,0 +1,5 @@
+{
+ "presets": [
+ ["env", { "modules": false } ]
+ ]
+}
diff --git a/activestorage/.codeclimate.yml b/activestorage/.codeclimate.yml
new file mode 100644
index 0000000000..18f3dbb7b5
--- /dev/null
+++ b/activestorage/.codeclimate.yml
@@ -0,0 +1,7 @@
+engines:
+ rubocop:
+ enabled: true
+
+ratings:
+ paths:
+ - "**.rb"
diff --git a/activestorage/.eslintrc b/activestorage/.eslintrc
new file mode 100644
index 0000000000..3d9ecd4bce
--- /dev/null
+++ b/activestorage/.eslintrc
@@ -0,0 +1,19 @@
+{
+ "extends": "eslint:recommended",
+ "rules": {
+ "semi": ["error", "never"],
+ "quotes": ["error", "double"],
+ "no-unused-vars": ["error", { "vars": "all", "args": "none" }]
+ },
+ "plugins": [
+ "import"
+ ],
+ "env": {
+ "browser": true,
+ "es6": true
+ },
+ "parserOptions": {
+ "ecmaVersion": 6,
+ "sourceType": "module"
+ }
+}
diff --git a/activestorage/.gitignore b/activestorage/.gitignore
new file mode 100644
index 0000000000..c5ff07cedd
--- /dev/null
+++ b/activestorage/.gitignore
@@ -0,0 +1,6 @@
+.byebug_history
+/node_modules
+test/dummy/db/*.sqlite3
+test/dummy/db/*.sqlite3-journal
+test/dummy/log/*.log
+test/dummy/tmp/
diff --git a/activestorage/.rubocop.yml b/activestorage/.rubocop.yml
new file mode 100644
index 0000000000..452e1b1e7f
--- /dev/null
+++ b/activestorage/.rubocop.yml
@@ -0,0 +1,125 @@
+AllCops:
+ TargetRubyVersion: 2.3
+ # RuboCop has a bunch of cops enabled by default. This setting tells RuboCop
+ # to ignore them, so only the ones explicitly set in this file are enabled.
+ DisabledByDefault: true
+ Exclude:
+ - '**/templates/**/*'
+ - '**/vendor/**/*'
+ - 'actionpack/lib/action_dispatch/journey/parser.rb'
+
+# Align `when` with `case`.
+Layout/CaseIndentation:
+ Enabled: true
+
+# Align comments with method definitions.
+Layout/CommentIndentation:
+ Enabled: true
+
+# No extra empty lines.
+Layout/EmptyLines:
+ Enabled: false
+
+# In a regular class definition, no empty lines around the body.
+Layout/EmptyLinesAroundClassBody:
+ Enabled: true
+
+# In a regular method definition, no empty lines around the body.
+Layout/EmptyLinesAroundMethodBody:
+ Enabled: true
+
+# In a regular module definition, no empty lines around the body.
+Layout/EmptyLinesAroundModuleBody:
+ Enabled: true
+
+# Method definitions after `private` or `protected` isolated calls need one
+# extra level of indentation.
+Layout/IndentationConsistency:
+ Enabled: true
+ EnforcedStyle: rails
+
+# Two spaces, no tabs (for indentation).
+Layout/IndentationWidth:
+ Enabled: true
+
+Layout/SpaceAfterColon:
+ Enabled: true
+
+Layout/SpaceAfterComma:
+ Enabled: true
+
+Layout/SpaceAroundEqualsInParameterDefault:
+ Enabled: true
+
+Layout/SpaceAroundKeyword:
+ Enabled: true
+
+Layout/SpaceAroundOperators:
+ Enabled: true
+
+Layout/SpaceBeforeFirstArg:
+ Enabled: true
+
+# Use `foo {}` not `foo{}`.
+Layout/SpaceBeforeBlockBraces:
+ Enabled: true
+
+# Use `foo { bar }` not `foo {bar}`.
+Layout/SpaceInsideBlockBraces:
+ Enabled: true
+
+# Use `{ a: 1 }` not `{a:1}`.
+Layout/SpaceInsideHashLiteralBraces:
+ Enabled: true
+
+Layout/SpaceInsideParens:
+ Enabled: true
+
+# Detect hard tabs, no hard tabs.
+Layout/Tab:
+ Enabled: true
+
+# Blank lines should not have any spaces.
+Layout/TrailingBlankLines:
+ Enabled: true
+
+# No trailing whitespace.
+Layout/TrailingWhitespace:
+ Enabled: true
+
+# Prefer &&/|| over and/or.
+Style/AndOr:
+ Enabled: true
+
+# Do not use braces for hash literals when they are the last argument of a
+# method call.
+Style/BracesAroundHashParameters:
+ Enabled: true
+ EnforcedStyle: context_dependent
+
+# Use Ruby >= 1.9 syntax for hashes. Prefer { a: :b } over { :a => :b }.
+Style/HashSyntax:
+ Enabled: true
+
+# Defining a method with parameters needs parentheses.
+Style/MethodDefParentheses:
+ Enabled: true
+
+# Check quotes usage according to lint rule below.
+Style/StringLiterals:
+ Enabled: true
+ EnforcedStyle: double_quotes
+
+# Use quotes for string literals when they are enough.
+Style/UnneededPercentQ:
+ Enabled: true
+
+# Align `end` with the matching keyword or starting expression except for
+# assignments, where it should be aligned with the LHS.
+Lint/EndAlignment:
+ Enabled: true
+ EnforcedStyleAlignWith: variable
+
+# Use my_method(my_arg) not my_method( my_arg ) or my_method my_arg.
+Lint/RequireParentheses:
+ Enabled: true
diff --git a/activestorage/.travis.yml b/activestorage/.travis.yml
new file mode 100644
index 0000000000..89edc05c78
--- /dev/null
+++ b/activestorage/.travis.yml
@@ -0,0 +1,25 @@
+language: ruby
+sudo: false
+bundler: true
+
+rvm:
+ - 2.3
+ - 2.4
+ - ruby-head
+
+cache:
+ bundler: true
+ yarn: true
+
+matrix:
+ allow_failures:
+ - rvm: ruby-head
+ fast_finish: true
+
+install:
+ - bundle install
+ - yarn install
+
+script:
+ - bundle exec rake
+ - yarn lint
diff --git a/activestorage/Gemfile b/activestorage/Gemfile
new file mode 100644
index 0000000000..b8b6e80176
--- /dev/null
+++ b/activestorage/Gemfile
@@ -0,0 +1,23 @@
+source "https://rubygems.org"
+
+git_source(:github) { |repo_path| "https://github.com/#{repo_path}.git" }
+
+gemspec
+
+gem "rails", github: "rails/rails"
+
+gem "rake"
+gem "byebug"
+
+gem "sqlite3"
+gem "httparty"
+
+gem "aws-sdk", "~> 2", require: false
+gem "google-cloud-storage", "~> 1.3", require: false
+# Contains fix to be able to test using StringIO
+gem 'azure-core', git: "https://github.com/dixpac/azure-ruby-asm-core.git"
+gem 'azure-storage', require: false
+
+gem "mini_magick"
+
+gem "rubocop", require: false
diff --git a/activestorage/Gemfile.lock b/activestorage/Gemfile.lock
new file mode 100644
index 0000000000..7388096778
--- /dev/null
+++ b/activestorage/Gemfile.lock
@@ -0,0 +1,233 @@
+GIT
+ remote: https://github.com/dixpac/azure-ruby-asm-core.git
+ revision: 4403389747f44a94b73e7a7522d1ea11f8b1a266
+ specs:
+ azure-core (0.1.8)
+ faraday (~> 0.9)
+ faraday_middleware (~> 0.10)
+ nokogiri (~> 1.7)
+
+GIT
+ remote: https://github.com/rails/rails.git
+ revision: 127b475dc251a06942fe0cd2de2e0545cf5ed69f
+ specs:
+ actioncable (5.2.0.alpha)
+ actionpack (= 5.2.0.alpha)
+ nio4r (~> 2.0)
+ websocket-driver (~> 0.6.1)
+ actionmailer (5.2.0.alpha)
+ actionpack (= 5.2.0.alpha)
+ actionview (= 5.2.0.alpha)
+ activejob (= 5.2.0.alpha)
+ mail (~> 2.5, >= 2.5.4)
+ rails-dom-testing (~> 2.0)
+ actionpack (5.2.0.alpha)
+ actionview (= 5.2.0.alpha)
+ activesupport (= 5.2.0.alpha)
+ rack (~> 2.0)
+ rack-test (~> 0.6.3)
+ rails-dom-testing (~> 2.0)
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
+ actionview (5.2.0.alpha)
+ activesupport (= 5.2.0.alpha)
+ builder (~> 3.1)
+ erubi (~> 1.4)
+ rails-dom-testing (~> 2.0)
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
+ activejob (5.2.0.alpha)
+ activesupport (= 5.2.0.alpha)
+ globalid (>= 0.3.6)
+ activemodel (5.2.0.alpha)
+ activesupport (= 5.2.0.alpha)
+ activerecord (5.2.0.alpha)
+ activemodel (= 5.2.0.alpha)
+ activesupport (= 5.2.0.alpha)
+ arel (~> 8.0)
+ activesupport (5.2.0.alpha)
+ concurrent-ruby (~> 1.0, >= 1.0.2)
+ i18n (~> 0.7)
+ minitest (~> 5.1)
+ tzinfo (~> 1.1)
+ rails (5.2.0.alpha)
+ actioncable (= 5.2.0.alpha)
+ actionmailer (= 5.2.0.alpha)
+ actionpack (= 5.2.0.alpha)
+ actionview (= 5.2.0.alpha)
+ activejob (= 5.2.0.alpha)
+ activemodel (= 5.2.0.alpha)
+ activerecord (= 5.2.0.alpha)
+ activesupport (= 5.2.0.alpha)
+ bundler (>= 1.3.0)
+ railties (= 5.2.0.alpha)
+ sprockets-rails (>= 2.0.0)
+ railties (5.2.0.alpha)
+ actionpack (= 5.2.0.alpha)
+ activesupport (= 5.2.0.alpha)
+ method_source
+ rake (>= 0.8.7)
+ thor (>= 0.18.1, < 2.0)
+
+PATH
+ remote: .
+ specs:
+ activestorage (0.1)
+ rails (>= 5.2.0.alpha)
+
+GEM
+ remote: https://rubygems.org/
+ specs:
+ addressable (2.5.1)
+ public_suffix (~> 2.0, >= 2.0.2)
+ arel (8.0.0)
+ ast (2.3.0)
+ aws-sdk (2.10.7)
+ aws-sdk-resources (= 2.10.7)
+ aws-sdk-core (2.10.7)
+ aws-sigv4 (~> 1.0)
+ jmespath (~> 1.0)
+ aws-sdk-resources (2.10.7)
+ aws-sdk-core (= 2.10.7)
+ aws-sigv4 (1.0.0)
+ azure-storage (0.11.4.preview)
+ azure-core (~> 0.1)
+ faraday (~> 0.9)
+ faraday_middleware (~> 0.10)
+ nokogiri (~> 1.6)
+ builder (3.2.3)
+ byebug (9.0.6)
+ concurrent-ruby (1.0.5)
+ declarative (0.0.9)
+ declarative-option (0.1.0)
+ digest-crc (0.4.1)
+ erubi (1.6.1)
+ faraday (0.12.1)
+ multipart-post (>= 1.2, < 3)
+ faraday_middleware (0.12.0)
+ faraday (>= 0.7.4, < 1.0)
+ globalid (0.4.0)
+ activesupport (>= 4.2.0)
+ google-api-client (0.13.0)
+ addressable (~> 2.5, >= 2.5.1)
+ googleauth (~> 0.5)
+ httpclient (>= 2.8.1, < 3.0)
+ mime-types (~> 3.0)
+ representable (~> 3.0)
+ retriable (>= 2.0, < 4.0)
+ google-cloud-core (1.0.0)
+ google-cloud-env (~> 1.0)
+ googleauth (~> 0.5.1)
+ google-cloud-env (1.0.1)
+ faraday (~> 0.11)
+ google-cloud-storage (1.3.0)
+ digest-crc (~> 0.4)
+ google-api-client (~> 0.13.0)
+ google-cloud-core (~> 1.0)
+ googleauth (0.5.1)
+ faraday (~> 0.9)
+ jwt (~> 1.4)
+ logging (~> 2.0)
+ memoist (~> 0.12)
+ multi_json (~> 1.11)
+ os (~> 0.9)
+ signet (~> 0.7)
+ httparty (0.15.5)
+ multi_xml (>= 0.5.2)
+ httpclient (2.8.3)
+ i18n (0.8.6)
+ jmespath (1.3.1)
+ jwt (1.5.6)
+ little-plugger (1.1.4)
+ logging (2.2.2)
+ little-plugger (~> 1.1)
+ multi_json (~> 1.10)
+ loofah (2.0.3)
+ nokogiri (>= 1.5.9)
+ mail (2.6.6)
+ mime-types (>= 1.16, < 4)
+ memoist (0.16.0)
+ method_source (0.8.2)
+ mime-types (3.1)
+ mime-types-data (~> 3.2015)
+ mime-types-data (3.2016.0521)
+ mini_magick (4.8.0)
+ mini_portile2 (2.2.0)
+ minitest (5.10.3)
+ multi_json (1.12.1)
+ multi_xml (0.6.0)
+ multipart-post (2.0.0)
+ nio4r (2.1.0)
+ nokogiri (1.8.0)
+ mini_portile2 (~> 2.2.0)
+ os (0.9.6)
+ parallel (1.11.2)
+ parser (2.4.0.0)
+ ast (~> 2.2)
+ powerpack (0.1.1)
+ public_suffix (2.0.5)
+ rack (2.0.3)
+ rack-test (0.6.3)
+ rack (>= 1.0)
+ rails-dom-testing (2.0.3)
+ activesupport (>= 4.2.0)
+ nokogiri (>= 1.6)
+ rails-html-sanitizer (1.0.3)
+ loofah (~> 2.0)
+ rainbow (2.2.2)
+ rake
+ rake (12.0.0)
+ representable (3.0.4)
+ declarative (< 0.1.0)
+ declarative-option (< 0.2.0)
+ uber (< 0.2.0)
+ retriable (3.0.2)
+ rubocop (0.49.1)
+ parallel (~> 1.10)
+ parser (>= 2.3.3.1, < 3.0)
+ powerpack (~> 0.1)
+ rainbow (>= 1.99.1, < 3.0)
+ ruby-progressbar (~> 1.7)
+ unicode-display_width (~> 1.0, >= 1.0.1)
+ ruby-progressbar (1.8.1)
+ signet (0.7.3)
+ addressable (~> 2.3)
+ faraday (~> 0.9)
+ jwt (~> 1.5)
+ multi_json (~> 1.10)
+ sprockets (3.7.1)
+ concurrent-ruby (~> 1.0)
+ rack (> 1, < 3)
+ sprockets-rails (3.2.0)
+ actionpack (>= 4.0)
+ activesupport (>= 4.0)
+ sprockets (>= 3.0.0)
+ sqlite3 (1.3.13)
+ thor (0.19.4)
+ thread_safe (0.3.6)
+ tzinfo (1.2.3)
+ thread_safe (~> 0.1)
+ uber (0.1.0)
+ unicode-display_width (1.3.0)
+ websocket-driver (0.6.5)
+ websocket-extensions (>= 0.1.0)
+ websocket-extensions (0.1.2)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ activestorage!
+ aws-sdk (~> 2)
+ azure-core!
+ azure-storage
+ bundler (~> 1.15)
+ byebug
+ google-cloud-storage (~> 1.3)
+ httparty
+ mini_magick
+ rails!
+ rake
+ rubocop
+ sqlite3
+
+BUNDLED WITH
+ 1.15.3
diff --git a/activestorage/MIT-LICENSE b/activestorage/MIT-LICENSE
new file mode 100644
index 0000000000..4e1c6cad79
--- /dev/null
+++ b/activestorage/MIT-LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2017 David Heinemeier Hansson, Basecamp
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/activestorage/README.md b/activestorage/README.md
new file mode 100644
index 0000000000..4a5f03233d
--- /dev/null
+++ b/activestorage/README.md
@@ -0,0 +1,151 @@
+# Active Storage
+
+Active Storage makes it simple to upload and reference files in cloud services, like Amazon S3 or Google Cloud Storage,
+and attach those files to Active Records. It also provides a disk service for testing or local deployments, but the
+focus is on cloud storage.
+
+Files can uploaded from the server to the cloud or directly from the client to the cloud.
+
+Image files can further more be transformed using on-demand variants for quality, aspect ratio, size, or any other
+MiniMagick supported transformation.
+
+## Compared to other storage solutions
+
+A key difference to how Active Storage works compared to other attachment solutions in Rails is through the use of built-in [Blob](https://github.com/rails/activestorage/blob/master/app/models/active_storage/blob.rb) and [Attachment](https://github.com/rails/activestorage/blob/master/app/models/active_storage/attachment.rb) models (backed by Active Record). This means existing application models do not need to be modified with additional columns to associate with files. Active Storage uses polymorphic associations via the join model of `Attachment`, which then connects to the actual `Blob`.
+
+These `Blob` models are intended to be immutable in spirit. One file, one blob. You can associate the same blob with multiple application models as well. And if you want to do transformations of a given `Blob`, the idea is that you'll simply create a new one, rather than attempt to mutate the existing (though of course you can delete that later if you don't need it).
+
+## Examples
+
+One attachment:
+
+```ruby
+class User < ApplicationRecord
+ has_one_attached :avatar
+end
+
+user.avatar.attach io: File.open("~/face.jpg"), filename: "avatar.jpg", content_type: "image/jpg"
+user.avatar.attached? # => true
+
+user.avatar.purge
+user.avatar.attached? # => false
+
+url_for(user.avatar) # Generate a permanent URL for the blob, which upon access will redirect to a temporary service URL.
+
+class AvatarsController < ApplicationController
+ def update
+ # params[:avatar] contains a ActionDispatch::Http::UploadedFile object
+ Current.user.avatar.attach(params.require(:avatar))
+ redirect_to Current.user
+ end
+end
+```
+
+Many attachments:
+
+```ruby
+class Message < ApplicationRecord
+ has_many_attached :images
+end
+```
+
+```erb
+<%= form_with model: @message do |form| %>
+ <%= form.text_field :title, placeholder: "Title" %>
+ <%= form.text_area :content %>
+
+ <%= form.file_field :images, multiple: true %>
+ <%= form.submit %>
+<% end %>
+```
+
+```ruby
+class MessagesController < ApplicationController
+ def index
+ # Use the built-in with_attached_images scope to avoid N+1
+ @messages = Message.all.with_attached_images
+ end
+
+ def create
+ message = Message.create! params.require(:message).permit(:title, :content)
+ message.images.attach(params[:message][:images])
+ redirect_to message
+ end
+
+ def show
+ @message = Message.find(params[:id])
+ end
+end
+```
+
+Variation of image attachment:
+
+```erb
+<%# Hitting the variant URL will lazy transform the original blob and then redirect to its new service location %>
+<%= image_tag url_for(user.avatar.variant(resize: "100x100")) %>
+```
+
+## Installation
+
+1. Add `gem "activestorage", git: "https://github.com/rails/activestorage.git"` to your Gemfile.
+2. Add `require "active_storage"` to config/application.rb, after `require "rails/all"` line.
+3. Run `rails activestorage:install` to create needed directories, migrations, and configuration.
+4. Configure the storage service in `config/environments/*` with `config.active_storage.service = :local`
+ that references the services configured in `config/storage_services.yml`.
+5. Optional: Add `gem "aws-sdk", "~> 2"` to your Gemfile if you want to use AWS S3.
+6. Optional: Add `gem "google-cloud-storage", "~> 1.3"` to your Gemfile if you want to use Google Cloud Storage.
+7. Optional: Add `gem "mini_magick"` to your Gemfile if you want to use variants.
+
+## Direct uploads
+
+Active Storage, with its included JavaScript library, supports uploading directly from the client to the cloud.
+
+### Direct upload installation
+
+1. Include `activestorage.js` in your application's JavaScript bundle.
+
+ Using the asset pipeline:
+ ```js
+ //= require activestorage
+ ```
+ Using the npm package:
+ ```js
+ import * as ActiveStorage from "activestorage"
+ ActiveStorage.start()
+ ```
+2. Annotate file inputs with the direct upload URL.
+
+ ```ruby
+ <%= form.file_field :attachments, multiple: true, direct_upload: true %>
+ ```
+3. That's it! Uploads begin upon form submission.
+
+### Direct upload JavaScript events
+
+| Event name | Event target | Event data (`event.detail`) | Description |
+| --- | --- | --- | --- |
+| `direct-uploads:start` | `