I'm trying to upload a file to my S3 bucket. Below I've set up my request with credentials. I'm having trouble deducing what should be in the headers and in the body. The secret acces key is within the signature. What am I missing?
def params
{
:key => key_prefix + file_name,
:aws_access_key_id => access_key_id,
:acl => "private",
:policy => encoded_policy,
:signature => encoded_signature
}
end
def headers
{
"Content-Type" => mime_type,
"x-amz-security-token" => session_token
}
end
def upload
connection.post do |req|
req.headers = headers
req.body = params.to_json
end
end
def connection
Faraday.new(:url => bucket_url) do |builder|
builder.request :multipart
builder.request :url_encoded
builder.adapter :typhoeus
end
end
The error I receive is:
<Error><Code>PreconditionFailed</Code><Message>At least one of the pre-conditions you
specified did not hold</Message><Condition>Bucket POST must be of the enclosure-type
multipart/form-data</Condition>