Question

Spaces Presigned POST

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, https://devcenter.heroku.com/articles/direct-to-s3-image-uploads-in-rails

It’s failing with this error:

<Error> 
    <Code>InvalidArgument</Code> 
    <Message>Missing access key</Message> 
    <BucketName>bucket</BucketName> 
    <RequestId>tx0000000000000000...</RequestId> 
    <HostId>1d183-nyc3a-nyc</HostId> 
</Error>

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


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Accepted Answer

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
    AWS.config(
      access_key_id: 'ACCESS_KEY_ID',
      secret_access_key: 'SECRET_ACCESS_KEY',
      s3_endpoint: 'nyc3.digitaloceanspaces.com',
      region: 'ny3'
    )

    bucket = AWS::S3.new.buckets['BUCKET-NAME']
    @s3_direct_post = bucket.presigned_post(
      key: "uploads/#{SecureRandom.uuid}/${filename}",
      success_action_status: '201',
      acl: 'public-read',
      content_type: ''
    )
  end
end
<%= 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 %>

This comment has been deleted

    John Gannon
    DigitalOcean Employee
    DigitalOcean Employee badge
    January 4, 2018

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

    Become a contributor for community

    Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

    DigitalOcean Documentation

    Full documentation for every DigitalOcean product.

    Resources for startups and SMBs

    The Wave has everything you need to know about building a business, from raising funding to marketing your product.

    Get our newsletter

    Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

    New accounts only. By submitting your email you agree to our Privacy Policy

    The developer cloud

    Scale up as you grow — whether you're running one virtual machine or ten thousand.

    Get started for free

    Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

    *This promotional offer applies to new accounts only.