您可以将此脚本用作代理,以使用 php curl 从 S3 获取图像。
$bucket = 'bucketname';
$filename = 'somefile.jpg';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://s3-<region>.amazonaws.com/' . $bucket . '/' . $filename);
curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
$data = curl_exec($ch);
curl_close($ch);
header("Content-Length: " . strlen($data));
echo $data;
例如与 .htaccess 结合RewriteRule
,然后您的 s3 存储桶 url 将被隐藏,并且可以简单地获取诸如此 url 之类的资源http://example.com/resources/images/somefile.jpg
RewriteRule ^resources/images/([^/]+)$ /proxy.php?filename=$1 [QSA,L]