rails carrierwave private files on S3 and cloudfront

后端 未结 3 784
遥遥无期
遥遥无期 2020-12-30 07:53

I have both public and private files which I server from Amazon cloudfront, the public files work fine but now I\'d like to secure some of them as private with an authentica

3条回答
  •  天命终不由人
    2020-12-30 08:18

    Depends how secure, but you can set file permissions on the particular Uploader Class itself overriding the default permissions like so:

    class SomeUploader < CarrierWave::Uploader::Base
    
      def fog_public
        false
      end
    
      def fog_authenticated_url_expiration
        5.minutes # in seconds from now,  (default is 10.minutes)
      end
      .....
    

    That will automatically cause the files from this Uploader to now be prepended with the temporary AWS expiration and accesskeys and future uploads will be set to private, ie not publicly accessible.

    https://s3.amazonaws.com/uploads/something/1234/124.pdf?AWSAccessKeyId=AKIAJKOSTQ6UXXLEWIUQ&Signature=4yM%2FF%2F5TV6t4b1IIvjseenRrb%2FY%3D&Expires=1379152321

提交回复
热议问题