Can use AWS Gem with Paperclip for DigitalOcean Spaces service?

Viewed 939

I tried to use aws-sdk + Paperclip gems with Ruby On Rails to use DigitalOcean Spaces to upload files

The problem i have is the result of configuration, i get "{name_buncket}.s3.nyc3.amazonaws.com" instead of "{name_buncket}.s3.nyc3.digitaloceanspaces.com", that last is the correct result to acces to DigitalOcean Spaces

The aws-sdk gem is exclusive for Amazon Services?, if that is the case, exist another gems similary to aws-sdk to use?

That is the configuration i use:

config.paperclip_defaults = {
    storage: :s3,
    url: '.....',
    s3_region: 'nyc3',
    s3_credentials: {
    bucket: '......',
    access_key_id: "......",
    secret_access_key: "........",
    s3_host_name: 'nyc3.digitaloceanspaces.com'
  }
}
3 Answers

In addition to setting s3_host_name, you'll also need to configure the endpoint used by the AWS SDK. Paperclip does not expose this directly, but it can be set through s3_options I am able to successfully use Paperclip with Spaces with the following config, where the env variable S3_HOST_NAME is set to nyc3.digitaloceanspaces.com:

  config.paperclip_defaults = {
    storage: :s3,
    bucket: ENV["S3_BUCKET"],
    s3_credentials: {
      access_key_id: ENV["S3_ACCESS_KEY_ID"],
      secret_access_key: ENV["S3_SECRET_ACCESS_KEY"]
    },
    s3_host_name: ENV["S3_HOST_NAME"],
    s3_host_alias: ENV["S3_HOST_ALIAS"],
    s3_region: ENV["S3_REGION"],
    s3_protocol: :https,
    s3_options: {
      endpoint: "https://" + ENV["S3_HOST_NAME"],
    },
    url: ":s3_alias_url",
    path: "/assets/:class/:attachment/:style/:filename",
  }

I think you're out of luck at the moment, although not for the hostname problem you're currently having.

The s3_host_name key should be outside of your s3_credentials block. If you change your configuration to this:

config.paperclip_defaults = {
  storage: :s3,
  url: '.....',
  s3_region: 'nyc3',
  s3_credentials: {
    bucket: '......',
    access_key_id: "......",
    secret_access_key: "........"
  },
  s3_host_name: 'nyc3.digitaloceanspaces.com'
}

you should fix your hostname problem.

However, at the moment this is just going to lead you to another problem: Paperclip/aws-sdk authentication isn't currently working with DigitalOcean Spaces - see this issue on GitHub.

I started the ticket for Paperclip and have one with Digital Ocean as well with no reply yet. The above example that drosboro entered should work in theory but it does not. Specifying s3_host_name does nothing and shows as the host name specified in the original post, though i do agree the issue must lie with a authentication issue somewhere.

To test, I switched to storage: :fog from :s3. Specifying scheme: 'https' results in a 403 response, while switching to scheme: 'http' results in a 302 response. Interestingly, using shows a file size in the json output while uploading via http results in 0. Odd.

Thinking maybe there were some newer API options used, I switched to AWS-SDK v3 which caused issues of it's own which I was able to work around. Still no dice, though. If i receive an update from anyone on this, I'll gladly post the response here.

Related