Is this the correct way to generate a URL and change it's download name?
$s3 = new AmazonS3();
$opt = array('response' => array('Content-Disposition' => 'attachment; "filename=newname.txt"'));
$url = $s3->get_object_url('bucket', 'file.txt', '5 minutes', $opt));
Apparently doesn't work with me.
There is no direct method to rename the file in s3. what do you have to do is copy the existing file with new name (Just set the target key) and delete the old one.
By default, when you upload the file with same name. It will overwrite the existing file. In case you want to have the previous file available, you need to enable versioning in the bucket.
Simply upload your new file on top of your old file to replace an old file in an S3 bucket. The existing file will be overwritten by your new file.
Your answer Yes, There's no option to rename bucket functionality for S3 because there are technically no folders in S3 so we have to handle every file within the bucket. Create a new bucket, copy the contents from the new bucket and delete the old bucket.
After several tests, apparently get_object_url requires Content-Disposition parameter to be in lower case.
Note that this is not the case for create_object which works case-insensitive.
So the working code for above is:
$opt = array('response' => array('content-disposition' => 'attachment; "filename=newname.txt"'));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With