2014-12-05 194 views
1

我試圖上傳文件到我的存儲桶。我能夠上傳Body,但不是SourceFile。這裏是我的方法:SourceFile亞馬遜AWS S3

$pathToFile='/explicit/path/to/file.jpg' 

// Upload an object by streaming the contents of a file 
$result = $s3Client->putObject(array(
      'Bucket'  => $bucket, 
      'Key'  => 'test.jpg', 
      'SourceFile' => $pathToFile, 
      'ACL' => 'public-read', 
      'ContentType' => 'image/jpeg' 
)); 

,但我得到這個錯誤:

You must specify a non-null value for the Body or SourceFile parameters. 

我已經嘗試不同類型的文件,並保持收到此錯誤。

+0

這可能是具有打開該文件的問題。試試''Body'=> fopen($ pathToFile,'r')',看看是否有打開文件的問題。 – 2014-12-05 17:40:32

+0

'Invalid resource type' is the error I get for that method – Riftus 2014-12-05 17:42:26

+0

那麼'var_dump(fopen($ pathToFile,'r'))'看起來像什麼?它不能返回有效的資源。 – 2014-12-05 20:47:54

回答

0

這個問題與不給好路徑有關。看起來像file_exists()只在本地檢查,這意味着它必須位於本地主機的索引內。

0

變化

'SourceFile' => $pathToFile, 

'Body' => $pathToFile,