Pre-Sign Uploads & Downloads in PHP

(without the SDK)

AWS S3 is an object-storage service from Amazon Web Services, allowing you to store files online around the world. For all intents and purposes, it’s infinitely scalable and fully managed – meaning you can upload objects without any setup or management burden. Think of it as a turbo-charged, pay-as-you-go FTP server that’s managed for you. There’s plenty of Desktop Clients that support it, plus you can access it programatically using their API or SDK.

Typically you need an access key and secret key to do anything with S3, although you can create pre-signed access credentials to allow someone else to perform a specific action on your behalf. This is called pre-signing.

If you are using S3 with PHP, you may wish create pre-signed upload requests so third-parties can directly upload to your S3 bucket with these special restricted credentials. You may also wish to allow people to directly download files using a similar method.

S3 Pre-Sign Upload Code

This PHP code allows you to create these pre-signed uploads, restricting the user to only uploading specifically named files:

The beauty of this code is that it doesn’t require the AWS SDK for PHP. It’s fully standalone – making it perfect for anyone who just wants to do some pre-signing and nothing else. It’s based on the AWS-provided specification.

Of course, if you want to use the SDK you can still do that. Here’s the official docs.

You can upload directly from a HTML Form in an end-user’s browser, using the required fields.

You could also upload server-side, or in a desktop-app, using a simple Python request:


S3 Pre-Signed Download Code

You can also pre-sign downloads, allowing others to download one of your files for a limited time. Here’s some standalone PHP code that can create the pre-signed GET URL:

Get the Broadcast Technology Newsletter

Sign up for the email newsletter about media and technology. Sent irregularly. No spam.

I'm Anthony Eden, and I'm a IT Professional, Broadcast Technician, Software Developer, and Solutions Engineer. I've been working in broadcast media since 2008, and developing software and websites for just as long. Right now, I provide freelance services through Media Realm - in particular, to the media and not-for-profit industries.

Follow Anthony on Twitter: @anthony_eden