views:

109

answers:

2

Hi,

I want to offer audio files for download on my site, after a user has completed a PayPal transaction. The commerce side of it is already written and working - the site is built in PHP with Zend Framework.

So that I don't incur large charges for storage and bandwidth, I'd like to host the files on a service like Amazon S3. However, I'm not sure if this is suitable for my requirements. Once the PayPal transaction is completed, I'd like to assign the user a unique id key of some kind, send them to a location where they enter the key, and the file they have bought is offered for download. The key would then expire.

I have no problem with writing the code to generate, store and delete the key. My question is this: how can I protect/hide a file stored on Amazon S3, and then offer it for download to an authorised user with a URL which subsequently becomes invalid, whilst also transferring the file directly from Amazon, rather than it passing through my server?

Is this possible, or do I need another solution?

+1  A: 

Amazon S3 has a "Pre-signed URL" feature which allows you to build a URL to access otherwise-protected content, with a time limit. On their documentation page, look for "Query String Request Authentication Alternative"

Andrew Aylett
Thanks Andrew - that looks like the right thing to do.I'm considering extending the Zend_Service_Amazon_S3 class to provide this functionality (creating and signing a URL with an expiry date). Do you know if anyone else has done this already?
George Crawford
Not a clue, I'm afraid.
Andrew Aylett
A: 

Admittedly I know very little about Amazon S3, but if you stored the file in a database in S3 and wrote a page that would serve the file from the database given a correct key. Then all you would have to do was to publish a web-service on S3 that you could call from your website to authorize a given key, and after that just redirect your user to the page that serves the file.

klausbyskov
Unfortunately, S3 doesn't work like that -- it's a static store, no scripting allowed. Amazon does also have cloud computing (EC2) but that's a separate service.
Andrew Aylett
@Andrew Aylett: Oh, I see. Then my answer makes little sense.
klausbyskov