我使用以下代码将对象放入AWS S3篮子中。
$temp = explode(".", $_FILES["file"]["name"]);
$_FILES["file"]["name"] = $newfilename = round(microtime(true)) . '.' . end($temp);
$filepath = $_FILES['file']['tmp_name'];
try {
$result = $this->Amazon->S3->putObject(array(
'Bucket' => 'mytest.sample',
'ACL' => 'authenticated-read',
'Key' => 'files/image/' . $id . '/' . $newfilename,
'ServerSideEncryption' => 'aws:kms',
'SourceFile' => $filepath,
'ContentType' => mime_content_type($filepath),
));
} catch (S3Exception $e) {
echo $e->getMessage() . "\n";
}
它工作正常。文件正在上传,但当我尝试删除文件空响应时,我得到了。 这是用于删除对象的代码。
try {
$result = $this->Amazon->S3->deleteMatchingObjects(array(
'Bucket' => 'mytest.sample',
//'Key' => 'files/image/' . $id . '/' . $fileName['Attachment']['attachment'],
'Key' => 'files/image/45/1441026402.docx', //static path for checking.
'VersionId' => 'latest',
));
} catch (S3Exception $e) {
echo $e->getMessage() . "\n";
}
我也试过以下方法
try {
$result = $this->Amazon->S3->deleteObject(array(
'Bucket' => 'mytest.sample',
//'Key' => 'files/image/' . $id . '/' . $fileName['Attachment']['attachment'],
'Key' => 'files/image/45/1441026402.docx',
'VersionId' => 'latest',
));
} catch (S3Exception $e) {
echo $e->getMessage() . "\n";
}
是否有任何许可问题?