zend框架为amazon S3 api提供了一个php包装器,简化了低级REST功能。
http://framework.zend.com/manual/en/zend.service.amazon.s3.html
例如,要在s3中存储文件,您需要做的就是
$s3->putFile("me.png", "my-own-bucket/Pictures/Me.png",
array(Zend_Service_Amazon_S3::S3_ACL_HEADER =>
Zend_Service_Amazon_S3::S3_ACL_PUBLIC_READ));
默认情况下,对象作为常规存储存储在存储桶中。 zend框架中是否有任何功能允许我指定对象在S3中存储为Reduced Redundancy Storage(RRS)?
如果没有,我可以将存储桶中所有对象的默认存储设置为RRS吗?
答案 0 :(得分:5)
http://docs.amazonwebservices.com/AmazonS3/latest/API/RESTObjectPOST.html
在RockyFords建议之后你有没有尝试过以下内容? 下面的代码应该以正确的模式上传。
$s3->putFile("me.png", "my-own-bucket/Pictures/Me.png",
array(
Zend_Service_Amazon_S3::S3_ACL_HEADER => Zend_Service_Amazon_S3::S3_ACL_PUBLIC_READ,
'x-amz-storage-class' => 'REDUCED_REDUNDANCY'
)
);
答案 1 :(得分:2)
看起来您可以将第三个参数传递给Zend_Services_S3::putFile and putObject
$meta
并且它接受标量或数组。
public function putFile($path, $object, $meta=null)
{
$data = @file_get_contents($path);
if ($data === false) {
/**
* @see Zend_Service_Amazon_S3_Exception
*/
require_once 'Zend/Service/Amazon/S3/Exception.php';
throw new Zend_Service_Amazon_S3_Exception("Cannot read file $path");
}
if (!is_array($meta)) {
$meta = array();
}
if (!isset($meta[self::S3_CONTENT_TYPE_HEADER])) {
$meta[self::S3_CONTENT_TYPE_HEADER] = self::getMimeType($path);
}
return $this->putObject($object, $data, $meta);
}
和S3只想更改标题以将对象或文件设置为RRS:
问:如何指定我想使用RRS存储数据?
Amazon S3中的所有对象都具有存储类设置。默认 设置是STANDARD。您可以在PUT请求中使用可选标头 指定设置REDUCED_REDUNDANCY。
你可能需要深入研究一下API以找到准确传递的内容,但这应该指向正确的方向。
答案 2 :(得分:0)
如果出现以下错误。在php.ini中简单地增加文件上传大小。默认是2 mb增加20mb或根据您的要求。
Error follows...
Exception: Zend_Service_Amazon_S3_Exception
Message: Cannot read file
Trace: #0 /var/www/html/cabapp/src/cabapp-cms/application/modules/default/controllers/DriverController.php(495): Zend_Service_Amazon_S3->putFile('', 'driver-license/...', Array)
#1 /var/www/html/cabapp/src/cabapp-cms/application/modules/default/controllers/DriverController.php(640): DriverController->_saveDriver()
#2 /var/www/html/Zend/Controller/Action.php(516): DriverController->addeditAction()
#3 /var/www/html/Zend/Controller/Dispatcher/Standard.php(308): Zend_Controller_Action->dispatch('addeditAction')
#4 /var/www/html/Zend/Controller/Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#5 /var/www/html/Zend/Application/Bootstrap/Bootstrap.php(101): Zend_Controller_Front->dispatch()
#6 /var/www/html/cabapp/src/lib/Ripple/Application/AbstractApplication.php(274): Zend_Application_Bootstrap_Bootstrap->run()
#7 /var/www/html/cabapp/src/cabapp-cms/cabapp-cms.php(33): Ripple\Application\AbstractApplication->run()
#8 /var/www/html/cabapp/src/cabapp-cms/application/webroot/index.php(44): require_once('/var/www/html/c...')
#9 {main}