Search code examples
ruby-on-railsrubyamazon-s3shrine

Configure the way file ID attribute is generated on Shrine gem


Shrine creates a random ID for the uploaded file to AWS S3 when calling presign_endpoint. Is there a way to change the way the ID is generated using Shrine's configuration?


Solution

  • Yes, you can use :presign_location:

    Shrine.plugin :presign_endopint, presign_location: -> (request) do
      "#{SecureRandom.hex}/#{request.params["filename"]}" # for example
    end