aws/aws-sdk-ruby — pull request #207 by vkill (2013-03-25 11:22:35+00:00)
Title: Ajax put upload SignatureDoesNotMatch bug solve

I want use ajax upload file to s3 with put method.

First, I generate s3 object write url use `aws-sdk`

```ruby
require 'aws-sdk'
AWS.config(
access_key_id: ENV['AWS_ACCESS_KEY_ID'],
secret_access_key: ENV['AWS_SECRET_ACCESS_KEY']
)
s3 = AWS::S3.new
bucket = s3.buckets[ENV['AWS_S3_BUCKET']]
obj = bucket.objects['tmp/file']
url = obj.url_for :write, expires: 3600
url.to_s
```

Second, i use ajax upload, use default options

the upload html: https://github.com/vkill/browser_upload_file_to_s3_demo/blob/master/public/upload_test.html

```javascript
$.ajax({
type: 'put',
url: url,
dataType: 'xml',
processData: false,
data: file
});
```

the result like this

>OPTIONS https://dev-playab-net.s3.amazonaws.com/tmp/file?AWSAccessKeyId=AKIAI6GLQRTI5FAZMNRA&Expires=1364064748&Signature=7TYtdwb%2BSVK%2FTwPIok%2FCuvWbYTw%3D 200 (OK)
>PUT https://dev-playab-net.s3.amazonaws.com/tmp/file?AWSAccessKeyId=AKIAI6GLQRTI5FAZMNRA&Expires=1364064748&Signature=7TYtdwb%2BSVK%2FTwPIok%2FCuvWbYTw%3D 403 (Forbidden)

```xml

SignatureDoesNotMatchThe request signature we calculated does not match the signature you provided. Check your key and signing method.50 55 54 0a 0a 61 70 70 6c 69 63 61 74 69 6f 6e 2f 78 2d 77 77 77 2d 66 6f 72 6d 2d 75 72 6c 65 6e 63 6f 64 65 64 3b 20 63 68 61 72 73 65 74 3d 55 54 46 2d 38 0a 31 33 36 34 30 36 34 37 34 38 0a 2f 64 65 76 2d 70 6c 61 79 61 62 2d 6e 65 74 2f 74 6d 70 2f 66 69 6c 65A2659C0EAF2E0BDDhGIUqnKQDXVpRyl98OdSjWTlrIdQF2HVFITulrLby4WTuSiq7NeDtRiUudjkhVOh7TYtdwb+SVK/TwPIok/CuvWbYTw=PUT

application/x-www-form-urlencoded; charset=UTF-8
1364064748
/dev-playab-net/tmp/fileAKIAI6GLQRTI5FAZMNRA
```

Third, i set Content-Type header and use ajax upload

```javascript
$.ajax({
type: 'put',
url: url,
dataType: 'xml',
processData: false,
data: file,
headers: {
'Content-Type': file.type
}
});
```

the result like this

>OPTIONS https://dev-playab-net.s3.amazonaws.com/tmp/file?AWSAccessKeyId=AKIAI6GLQRTI5FAZMNRA&Expires=1364064748&Signature=7TYtdwb%2BSVK%2FTwPIok%2FCuvWbYTw%3D 200 (OK)

>PUT https://dev-playab-net.s3.amazonaws.com/tmp/file?AWSAccessKeyId=AKIAI6GLQRTI5FAZMNRA&Expires=1364064748&Signature=7TYtdwb%2BSVK%2FTwPIok%2FCuvWbYTw%3D 403 (Forbidden)

```xml

SignatureDoesNotMatchThe request signature we calculated does not match the signature you provided. Check your key and signing method.50 55 54 0a 0a 61 70 70 6c 69 63 61 74 69 6f 6e 2f 78 2d 72 75 62 79 0a 31 33 36 34 30 36 34 37 34 38 0a 2f 64 65 76 2d 70 6c 61 79 61 62 2d 6e 65 74 2f 74 6d 70 2f 66 69 6c 655C3072B338FDF1BEZMaN/ccYiRE61ZOzbApu8iZaFyO/YTyGG7LfZDAtKZGNv3oX0S9dAOUBj/uHjR7p7TYtdwb+SVK/TwPIok/CuvWbYTw=PUT

application/x-ruby
1364064748
/dev-playab-net/tmp/fileAKIAI6GLQRTI5FAZMNRA
```

So, i view source, https://github.com/aws/aws-sdk-ruby/blob/master/lib/aws/s3/s3_object.rb#L1340 and https://github.com/aws/aws-sdk-ruby/blob/master/lib/aws/s3/request.rb#L93 , discover `s3_object#string_to_sign` error, missing 'content-md5' header and 'content-type' header.

I already solved it, please merge.

Thanks.