Question

I have 2 models that I want CarrierWave to interact with. Item and Image models.

What I want to happen is once the user uploads their item to S3 via Carrierwave - that part is pretty straight forward - whenever another user wants to download the item, they press a button that triggers some method that dynamically generates a download link - that expires when 2 conditions are met. Either the item is downloaded X number of times, or X hours have passed (say 24 hours).

The idea being that there isn't a static download link floating around on the internet to that file.

How do I do that?

Was it helpful?

Solution

CarrierWave allows you to set the fog_public and fog_authenticated_url_expiration options both for every uploader (through an initializer) or on a specific uploader. In the latter case you just place self.fog_public = false and self.fog_authenticated_url_expiration = 123 inside your uploader class definition. With these two options set, any calls to model.uploader.url will return a specially built URL that will expire after the set amount of time.

OTHER TIPS

I'm pretty sure you can only limit the amount of time on an s3 image. you can't limit the number of downloads.

http://docs.aws.amazon.com/AmazonS3/latest/dev/S3_QSAuth.html talks some about it. If you generate with https then it will be hard to sniff and likely you will be safe. You could build your own front end to s3 but then you would have to track the URL, count the downloads and stop it yourself. I'd think hard about that. bytes are not that expensive (IMHO)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top