【发布时间】:2015-02-03 23:02:12
【问题描述】:
我正在尝试将文件上传到我的存储桶。我可以使用 Body 但不能使用 SourceFile 上传。这是我的方法:
$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.
我尝试了不同类型的文件并不断收到此错误。
【问题讨论】:
-
打开文件可能有问题。试试
'Body' => fopen($pathToFile, 'r')看看打开文件是否有问题。 -
Invalid resource type是我使用该方法得到的错误 -
那么
var_dump(fopen($pathToFile, 'r'))是什么样的?它不能返回有效的资源。
标签: php api amazon-web-services amazon-s3