PHP Amazon SDK-s3 putObject始终返回403
我正在尝试集成PHP Amazon SDK-S3API。我正在提供正确的凭证。但我不确定putObject参数。 这是我尝试的代码:PHP Amazon SDK-s3 putObject始终返回403,php,amazon-web-services,amazon-s3,Php,Amazon Web Services,Amazon S3,我正在尝试集成PHP Amazon SDK-S3API。我正在提供正确的凭证。但我不确定putObject参数。 这是我尝试的代码: try { $s3Client->putObject(array( 'Bucket' => $bucket, 'Key' => $filename, 'Body' => file_get_contents(drupal_realpath($file_path)), 'AC
try {
$s3Client->putObject(array(
'Bucket' => $bucket,
'Key' => $filename,
'Body' => file_get_contents(drupal_realpath($file_path)),
'ACL' => 'public-read',
));
} catch (S3Exception $e) {echo '<pre>';print_r($e);
echo "There was an error uploading the file.\n";
}
exit;
$e->getMessage()
说了什么?用户拥有这个bucket吗?此外,凭据是否来自IAM用户?如果是,他们的策略是否允许putObject操作?不要使用file\u get\u contents()
,这样会不必要地将整个文件加载到内存中。Do'Body'=>fopen(drupal\u realpath($file\u path)、'r')
或'SourceFile'=>drupal\u realpath($file\u path)
Aws\S3\Exception\AccessDeniedException Object
(
[response:protected] => Guzzle\Http\Message\Response Object
(
[body:protected] => Guzzle\Http\EntityBody Object
(
[contentEncoding:protected] =>
[rewindFunction:protected] =>
[stream:protected] => Resource id #219
[size:protected] =>
[cache:protected] => Array
(
[wrapper_type] => PHP
[stream_type] => TEMP
[mode] => w+b
[unread_bytes] => 0
[seekable] => 1
[uri] => php://temp
[is_local] => 1
[is_readable] => 1
[is_writable] => 1
)
[customData:protected] => Array
(
)
)
[reasonPhrase:protected] => Forbidden
[statusCode:protected] => 403
[info:protected] => Array
(
[url] => https://s3.amazonaws.com/my_test/ak1.jpg
[content_type] => application/xml
[http_code] => 403
[header_size] => 273
[request_size] => 320
[filetime] => -1
.........................................................................................................