13

嗨,我正在尝试使用以下代码将新对象放入存储桶中:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); 

require_once(FCPATH.'s3/aws-autoloader.php');

use Aws\S3\S3Client;

class s3{
    public $_secret_key ="********";
    public $_access_key = "********"; 
    public $_bucket = "tphotos-dev";

 function connect(){

     return  S3Client::factory(array(
    'key'    => $this->_access_key,
    'secret' => $this->_secret_key,
));


 }
 function deleteObject($prefix = false){
    if($prefix){
        $s3 = $this->connect();
        return $s3->deleteMatchingObjects($this->_bucket, $prefix);
    }
 }

 function putObject($file_name,$source_file){
    $s3 = $this->connect();
     $s3->putObject(array(
    'Bucket' => (string)$this->_bucket,
    'Key'    => $file_name,
    'SourceFile'   => $source_file,
    'ACL'         => 'public-read',
    ));
    return $s3->waitUntilObjectExists(array(
    'Bucket' => $this->_bucket,
    'Key'    => $file_name
    ));

 }  

}

?>

所以一旦我这样做:

$s3->putObject('myfilename.jpg',get_file_content("temp/image.jpg"));

它返回错误:

Fatal error: Uncaught exception 'Aws\Common\Exception\InvalidArgumentException' with message 'You must specify a non-null value for the Body or SourceFile parameters.' in /Users/ok/Projects/s3/Aws/Common/Client/UploadBodyListener.php:91 

有什么线索吗?

4

1 回答 1

27

对不起,我得到了修复:

只是为了改变这一点

'SourceFile'   => $source_file,

'Body'   => $source_file,
于 2013-08-21T21:29:00.000 回答