亚马逊S3不缓存图片 [英] Amazon S3 not caching images
问题描述
我使用的是亚马逊S3 PHP类上传图片,但缓存头没有被设置。下面是我使用的电话。
$ S3-> putObjectFile(
$映像位置,
bucketname
$映像文件,
S3 :: ACL_PUBLIC_READ,
阵列(
缓存控制=> 最大年龄= 315360000,
过期=> gmdate(D,D M Y H:我:秒T,的strtotime(+ 5年))
)
);
头部响应我得到了上传的图片:
日期:星期二,2011年10月4日四点21分09秒格林尼治标准时间 的X AMZ-请求ID:B6BAAAAD9B460160 内容长度:34319 的X AMZ-ID-2:Oxxx1hIG2nNKfff3vgH / XX / dffF59O / 7a1UWrKrgZlju2g / 8WvTcBpccYToULbm 最后一次修改:星期二,2011年10月4日四时19分二十秒GMT 服务器:AmazonS3 ETag的:4846afffbc1a7284fff4a590d5acd6cd 内容类型:图像/ JPEG 接受-范围:字节
我不熟悉的亚马逊S3 PHP类而是一个快速浏览一下文档显示, putObjectFile
法德preciated,你应该使用 putObject
代替。
< PHP
//将任何与自定义标题:
$把= S3 :: putObject(
S3 :: INPUTFILE($文件)
$桶,
$ URI,
S3 :: ACL_PUBLIC_READ,
阵列(),
阵列(//自定义$ requestHeaders
缓存控制=> 最大年龄= 315360000,
过期=> gmdate(D,D M Y H:我:秒T,的strtotime(+ 5年))
)
);
后续代码var_dump($放);
?>
但是,为什么不考虑使用官方亚马逊SDK的PHP ?
您会使用 create_object
来上传文件。该 有一些很好的例子官方的文档:
//实例化类
$ S3 =新AmazonS3();
$响应= $ S3-> create_object('我斗,上传/ I \'维生素E现在已经üpløådéd.txt',阵列(
'文件上传'=> upload_me.txt,
ACL=> AmazonS3 :: ACL_PUBLIC,
'的contentType => text / plain的,
'存储'=> AmazonS3 :: STORAGE_REDUCED,
'头'=>阵列(//原标题
缓存控制'=> 最大年龄,
'内容编码'=> GZIP,
内容语言=> EN-US,
'过期'=> 星期四,1994年12月1日16:00:00 GMT,
),
元=>阵列(
'字'=> 去你妈',//的x AMZ-元字
冰宝宝=> 太冷了,太冷//的x AMZ-元冰的冰宝宝
),
));
// 成功?
的var_dump($响应 - > isOK());
I'm using the Amazon S3 PHP Class to upload images, but the cache headers aren't being set. Here's the call I'm using.
$s3->putObjectFile(
$image_location,
"bucketname",
$image_file_name,
S3::ACL_PUBLIC_READ,
array(
"Cache-Control" => "max-age=315360000",
"Expires" => gmdate("D, d M Y H:i:s T", strtotime("+5 years"))
)
);
The header response I'm getting for the uploaded image is:
Date: Tue, 04 Oct 2011 04:21:09 GMT x-amz-request-id: B6BAAAAD9B460160 Content-Length: 34319 x-amz-id-2: Oxxx1hIG2nNKfff3vgH/xx/dffF59O/7a1UWrKrgZlju2g/8WvTcBpccYToULbm Last-Modified: Tue, 04 Oct 2011 04:19:20 GMT Server: AmazonS3 ETag: "4846afffbc1a7284fff4a590d5acd6cd" Content-Type: image/jpeg Accept-Ranges: bytes
I am not familiar with the Amazon S3 PHP Class but a quick look at the documentation reveals that the putObjectFile
method is depreciated and you should use putObject
instead.
<?php
// PUT with custom headers:
$put = S3::putObject(
S3::inputFile($file),
$bucket,
$uri,
S3::ACL_PUBLIC_READ,
array(),
array( // Custom $requestHeaders
"Cache-Control" => "max-age=315360000",
"Expires" => gmdate("D, d M Y H:i:s T", strtotime("+5 years"))
)
);
var_dump($put);
?>
But why not consider using the official Amazon SDk for PHP?
You would use create_object
to upload a file. The official docs have some good examples:
// Instantiate the class
$s3 = new AmazonS3();
$response = $s3->create_object('my-bucket', 'üpløåd/î\'vé nøw béén üpløådéd.txt', array(
'fileUpload' => 'upload_me.txt',
'acl' => AmazonS3::ACL_PUBLIC,
'contentType' => 'text/plain',
'storage' => AmazonS3::STORAGE_REDUCED,
'headers' => array( // raw headers
'Cache-Control' => 'max-age',
'Content-Encoding' => 'gzip',
'Content-Language' => 'en-US',
'Expires' => 'Thu, 01 Dec 1994 16:00:00 GMT',
),
'meta' => array(
'word' => 'to your mother', // x-amz-meta-word
'ice-ice-baby' => 'too cold, too cold' // x-amz-meta-ice-ice-baby
),
));
// Success?
var_dump($response->isOK());
这篇关于亚马逊S3不缓存图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!