title: AWS Ruby SDK CORE: Upload files to S3
body: <p>I want to upload a file (any file, could be a .txt, .mp4, .mp3, .zip, .tar ...etc) to AWS S3 using <a href="http://docs.aws.amazon.com/sdkforruby/api/frames.html" rel="noreferrer">AWS-SDK-CORE ruby SDK</a></p>
  
  <p>Here is my code:</p>
  
  <pre><code>require 'aws-sdk-core'
  Aws.config = {
    :access_key_id =&gt; MY_ACCESS_KEY
    :secret_access_key =&gt; MY_SECRET_KEY,
    :region =&gt; 'us-west-2'
  }
  
  s3 = Aws::S3.new
  resp = s3.put_object(
    :bucket =&gt; "mybucket",
    :key =&gt; "myfolder/upload_me.sql",
    :body =&gt; "./upload_me.sql"
  )
  </code></pre>
  
  <p>Now, Above code runs and creates a key <code>myfolder/upload_me.sql</code> which has only one line written and that is <code>./upload_me.sql</code> which is wrong. The file <code>upload_me.sql</code> has several lines.</p>
  
  <p>Expected behaviour is to upload the file <code>upload_me.sql</code> on S3 as <code>mybucket/myfolder/upload_me.sql</code>. But instead it just writes one line to <code>mybucket/myfolder/upload_me.sql</code> and that is <code>./upload_me.sql</code></p>
  
  <p>Now, If I omit the <code>:body</code> part as below:</p>
  
  <pre><code>s3 = Aws::S3.new
  resp = s3.put_object(
    :bucket =&gt; "mybucket",
    :key =&gt; "myfolder/upload_me.sql",
  )
  </code></pre>
  
  <p>Then it just creates and empty key called <code>mybucket/myfolder/upload_me.sql</code> which is not even downloadable (well, even if it gets downloaded, it is useless)</p>
  
  <p>Could you point me where I am going wrong?</p>
  
  <p>Here is ruby-SDK-core documentation for <code>put_object</code> Method: <a href="http://docs.aws.amazon.com/sdkforruby/api/Aws/S3/V20060301.html#put_object-instance_method" rel="noreferrer">http://docs.aws.amazon.com/sdkforruby/api/Aws/S3/V20060301.html#put_object-instance_method</a></p>
  
  <p><strong>UPDATE:</strong>
  If I try to upload the same file using AWS-CLI, it gets uploaded fine. Here is the command:</p>
  
  <pre><code>aws s3api put-object --bucket mybucket --key myfolder/upload_me.sql --body ./upload_me.sql
  </code></pre>