I am using amazon S3 service with PHP by using this API
https://github.com/tpyo/amazon-s3-php-class I am passing the url to client like thishttps://domain.s3.amazonaws.com/bucket/filename_11052011111924.zip?AWSAccessKeyId=myaccesskey&Expires=1305311393&Signature=mysignature
So when the cl开发者_如何学JAVAient clicks or paste the URL into browser , the file downloaded with the name of filename_11052011111924.zip.But I stored my original filename in DB.
So is it possible to download when passing the URL alone to the client and download with original file name.I am not sure whether this will help me.
Content-Disposition: attachment; filename=FILENAME.EXT
Content-Type: application/octet-stream
If you set the headers that you listed on your file when you upload it to S3, you will be able to download the file with the original filename. (you can also set these on existing files in S3 - see the AWS docs)
I'm not sure if your library supports this but you can do it with the AWS S3 SDK.
Something like (I don't know php so check the syntax):
// Instantiate the class
$s3 = new AmazonS3();
$response = $s3->create_object('bucket', 'filename_11052011111924.zip', array(
'fileUpload' => 'filename.zip',
'contentType' => 'application/octet-stream',
'headers' => array( // raw headers
'Content-Disposition' => 'attachment; filename=filename.zip',
),
));
Update
You can also adjust certain headers each time you generate a new url. See http://docs.amazonwebservices.com/AWSSDKforPHP/latest/#m=AmazonS3/get_object_url
$url = $s3->get_object_url('bucket', 'filename_11052011111924.zip', '5 minutes', array(
'response' => array(
'Content-Disposition' => 'attachment; filename=filename.zip'
)
));
I don't think that will work (I never tried it though). You might need to download the file to your server first, later use headers, once it is completed (or after sometime later with some bot or cron) you can delete the file(s).
This approach will be using your bandwidth.
Yes, you can tell to AWS how output file must be named:
Note: we encode file name!
$filename = "Here we can have some utf8 chars.ext";
$outputFileName = '=?UTF-8?B?' . base64_encode($filename) . '?=';
$url = $s3->get_object_url(
'bucket_name',
'path_to_the_file.ext',
'5 minutes',
array(
'response' => array(
'content-disposition' => 'attachment;' . " filename=\"" . $outputFileName . "\";")
)
)
);
精彩评论