Php 使用laravel 5.6从s3删除文件
我想以编程的方式从我的bucket中删除文件,但这并没有发生 我有下面的代码Php 使用laravel 5.6从s3删除文件,php,laravel,amazon-s3,Php,Laravel,Amazon S3,我想以编程的方式从我的bucket中删除文件,但这并没有发生 我有下面的代码 $s3 = \Storage::disk('s3'); $existingImagePath = $studentPortfolios[$i]->portfolio_link; // this returns the path of the file stored in the db $s3->delete($existingImagePath); 但这并不是从bucket中删除文件 我必须暂时为每个人向
$s3 = \Storage::disk('s3');
$existingImagePath = $studentPortfolios[$i]->portfolio_link; // this returns the path of the file stored in the db
$s3->delete($existingImagePath);
但这并不是从bucket中删除文件
我必须暂时为每个人向bucket写入objects权限,因为我正在从本地设置运行它
请注意:-我可以上传文件,但删除不起作用
关于这方面的任何建议都会非常有用。您是否尝试使用aws s3 cli命令删除存储桶中的文件,并查看它是否有效 示例:aws s3 rm s3://bucket name/--递归
如果它能工作,那么您可能需要修复代码中的问题。我已经处理了下面的代码
use Aws\S3\S3Client;
use Aws\S3\Exception\S3Exception;
$bucket = "bucket";
$keyname = "keyname";
$s3 = new S3Client([
'version' => 'latest',
'region' => 'region'
]);
$result = $s3->deleteObject(array(
'Bucket' => $bucket,
'Key' => $keyname
));
这就像从磁盘删除文件一样。在laravel文档中选中此项:
确保文件具有删除权限。如果没有,则通过选择文件或目录并从s3中的操作中选择“公开”选项,从s3中授予权限。编辑您从s3获得的带有响应对象的问题。有一条关于发生了什么的消息。@Dhaval Chheda可能在bucket中缺少删除权限。从其他方面看,您的路径不正确,但代码不正确right@Tpojka没有消息它只是不删除你应该总是得到一些响应,无论是否有错误,是否有成功的行动。用这个试试,或者在Try catch块中设置最后一行。这是一个非常适合我的解决方案,它可以直接工作。。因此,代码中有一些内容,但不知道如何修复它
$imageName = $studentPortfolios[$i]->portfolio_link; // this returns the file name stored in the DB
\Storage::disk('s3')->delete('s3_folder_path/'. $imageName);