Spaces Presigned POST

October 3, 2017 3.4k views
Object Storage

Using the ruby aws-sdk gem, presigned post uploads work correctly with AWS S3 proper and fail when attempting on Spaces. So there is some kind of non-interoperability going on.

I setup everything following this guide,

It’s failing with this error:

    <Message>Missing access key</Message> 

Again, the code works with S3, fails with Spaces. Has anyone got this to work?

5 Answers

Here is a working example using the aws-sdk-v1 gem, which is required until Spaces supports v4 signatures.

class FoobarController < ApplicationController
  layout false

  def index
      access_key_id: 'ACCESS_KEY_ID',
      secret_access_key: 'SECRET_ACCESS_KEY',
      s3_endpoint: '',
      region: 'ny3'

    bucket =['BUCKET-NAME']
    @s3_direct_post = bucket.presigned_post(
      key: "uploads/#{SecureRandom.uuid}/${filename}",
      success_action_status: '201',
      acl: 'public-read',
      content_type: ''
<%= form_tag(@s3_direct_post.url.to_s, enctype: 'multipart/form-data', authenticity_token: false, enforce_utf8: false) do %>
    <% @s3_direct_post.fields.each do |field, value| %>
        <%= hidden_field_tag field, value %>
    <% end %>
    <%= file_field_tag :file %>
    <%= submit_tag 'Upload' %>
<% end %>

I found this post on the DigitalOcean UserVoice, which answers why. Presigned POST with the v4 signature does not work, you must use the v2 signature. I’ve yet to find a way to force the aws-sdk gem to use the v2 signature so I’ll be waiting for v4 support.

@PDGBen we now have v4 support in NYC3, and soon will have the same in AMS3. HTH

Please let me know if DigitalOcean supports the “Policy” and “X-Amz-Signature” headers? (AWS V4) TIA.

Have another answer? Share your knowledge.