Remove signatures from URLs in AWS Carrierwave to speed up loading

Viewed 22

I'm uploading lots of images to S3 with Carrierwave, but my URLS contain aws signatures which leads to very slow loading times.

When retrieving a JSON with 200 records, each image url looks like this:

"url":"https://.s3.eu-west-3.amazonaws.com/uploads/product/images/1156/1.jpg?X-Amz-Algorithm=AWS4-HMAC-SHA256\u0026X-Amz-Credential=XXX%2Feu-west-3%2Fs3%2Faws4_request\u0026X-Amz-Date=20220921T151258Z\u0026X-Amz-Expires=604800\u0026X-Amz-SignedHeaders=host\u0026X-Amz-Signature=XXXX

¿How can I sign all of the bucket globally or remove the signature from each url?

I've tried config.fog_public = false, config.aws_acl = :authenticated_read with no luck.

Carrierwave.rb

CarrierWave.configure do |config|
  config.storage    = :aws
  config.aws_bucket = ENV['S3_BUCKET_NAME'] # for AWS-side bucket access permissions config, see section below
  config.aws_acl    = :authenticated_read
  config.fog_public = false

  # Optionally define an asset host for configurations that are fronted by a
  # content host, such as CloudFront.

  config.aws_authenticated_url_expiration = 60 * 60 * 24 * 7

  # Set custom options such as cache control to leverage browser caching.
  # You can use either a static Hash or a Proc.
  config.aws_attributes = -> { {
    expires: 1.week.from_now.httpdate,
    cache_control: 'max-age=604800'
  } }

  config.aws_credentials = {
    access_key_id:     ENV['AWS_ACCESS_KEY_ID'],
    secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'],
    region:            ENV['AWS_REGION'], # Required
    stub_responses:    Rails.env.test? # Optional, avoid hitting S3 actual during tests
  }

  # Optional: Signing of download urls, e.g. for serving private content through
  # CloudFront. Be sure you have the `cloudfront-signer` gem installed and
  # configured:
  # config.aws_signer = -> (unsigned_url, options) do
  #   Aws::CF::Signer.sign_url(unsigned_url, options)
  # end
end
0 Answers
Related