2014-12-05 193 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,