Php 源文件AmazonAWSS3
我正试图上传一个文件到我的bucket中。我可以上传正文,但不能上传源文件。以下是我的方法:Php 源文件AmazonAWSS3,php,api,amazon-web-services,amazon-s3,Php,Api,Amazon Web Services,Amazon S3,我正试图上传一个文件到我的bucket中。我可以上传正文,但不能上传源文件。以下是我的方法: $pathToFile='/explicit/path/to/file.jpg' // Upload an object by streaming the contents of a file $result = $s3Client->putObject(array( 'Bucket' => $bucket, 'Key'
$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.
我尝试了不同类型的文件,但不断出现此错误。问题与没有提供好的路径有关。看起来文件_exists()只在本地检查,这意味着它必须在本地主机的索引中。更改
'SourceFile' => $pathToFile,
到
它可能在打开文件时遇到问题。请尝试
'Body'=>fopen($pathToFile,'r')
,查看打开文件时是否有任何问题。无效的资源类型是该方法的错误。变量转储(fopen($pathToFile,'r'))
是什么样子?它不能返回有效的资源。
'Body' => $pathToFile,