Question

So I have an upload service with many people uploading the same files to my Amazon S3 bucket. I changed my app design so the SHA1 of the file is calculated upon upload and checked against the list of uploaded files.

If it exists, I simply assign the file to the new uploader as well.

The problem with this is, the file being named as the first uploader named it. All subsequent uploaders will get the same first name.

I can use download="" attribute in HTML5 but it doesn't work in IE: http://caniuse.com/#search=download

The files are stored remotely so I can't change the header unless I download it first to my local server which is illogical.

Please advice.

Was it helpful?

Solution

The only way I see this possible is to add a meta-data just before redirecting user to download.

You can add meta-data to your files in S3. With key as "Content-Disposition" and value as 'attachment; filename="~actual file name~"'. You can force the name and trigger download.

This way, you don't have to download any files to local file system.

The caveat to this is if someone else is also requesting the same file with in milli-seconds, first user might get the name as requested by second user.

OTHER TIPS

use the rename() method

example:

$file = "boo.png";
$newName = "scary";
$ext = substr( $file, strpos( "." ), strlen( $file ) );
$path = "/images/downloaded/";

rename($path . $file, $path . $newName . $ext);

php documentation

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