2013-08-21 12 views
12

hallo ich versuche, mit diesem Code ein neues Objekt in einen Eimer setzen:PHP Amazon SDK - s3 putObject und stellt Körper

<?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 
    )); 

} 

} 

>

so, wenn ich zum Beispiel so tun:

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

es gibt Fehler:

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 

jede Anhaltspunkt?

+0

In meinem Fall zu ändern war, weil ich eine Grenze für hatte ** upload_max_filesize * * und ** post_max_size ** weil $ source_file nicht kommt (ist null), validiert der Server $ source_file> upload_max_filesize oder post_max_size. –

Antwort

27

Leider i das Update bekam:

war es gerade diese es

'SourceFile' => $source_file, 

zu

'Body' => $source_file, 
+0

Gute Arbeit, Danke – Elby

+0

Hallo Könnten Sie bitte mir helfen. Wenn ich versuche, dieselbe Funktion zu benutzen, bekomme ich eine Antwort von 403. – ARUN

+0

Danke @sbaaaang, aber warum? Dokumentation sagt http://docs.aws.amazon.com/aws-sdk-php/v2/guide/service-s3.html#uploading-a-file Version sdk 2 –