title: Upload file to S3 from rails server
body: <p>I would like to upload a file to an Amazon S3 bucket from a rails app. The file comes via a user uploading it. I am having difficulty finding the proper documentation for this because of the different versions of the aws-sdk. Additionally, the <code>acl: :public_read</code> is intentional. I only want authorized users uploading, but anyone should be able to access it.</p>
  <p>My current problem is that I am <em>unable to index into a lazy loaded collection</em>. Google provides no useful information for how to not load it lazily.</p>
  <p>Here is my relevant code. Note that the controller actions for <code>new</code> and <code>show</code> are empty for now.</p>
  <h1>messages_controller.rb</h1>
  <pre><code>  def create
      # Creates the file object
      obj = $S3.bucket(TEST_BUCKET).objects[params[:file].original_filename]
  
      # Uploads the file
      obj.write(
         file: params[:file],
         acl: :public_read
      )
    end
  </code></pre>
  <h1>new.html.erb</h1>
  <pre><code>&lt;h1&gt;Upload a file&lt;/h1&gt;
  
  &lt;%= form_tag messages_path, enctype: 'multipart/form-data' do %&gt;
    &lt;%= file_field_tag :file  %&gt;
    &lt;%= submit_tag 'Upload file' %&gt;
  &lt;% end %&gt;
  </code></pre>
  <p>I am using restful routes so the only relevant routing info is <code>  resources :messages</code></p>
  <p>I am running rails 6.0.0beta, not that it should matter. I am using version 3 of the aws-sdk gem.</p>