问题描述
长期以来,我一直在努力解决一个极其琐碎的问题,但是没有运气.
I am trying to solve an extremely trivial issue since long but no luck.
我想从PHP WebServer将文件上传到AWS S3之后立即删除文件.步骤如下:
I want to delete a file immediately after uploading it to AWS S3 from a PHP WebServer. Following are the steps:
//Upload file to S3 using PHP SDK's S3Client::putObject method:
$result = $s3_client->putObject( array(
'Bucket' => AWS_BUCKET_NAME,
'Key' => $file_name,
'SourceFile' => $file_path,
'Metadata' => array(
'metadata_field' => 'metadata_value'
)
));
//Poll the object until it is accessible
$s3_client->waitUntil('ObjectExists', array(
'Bucket' => AWS_BUCKET_NAME,
'Key' => $file_name
));
//Delete the file
unlink( $file_path );
如果我上传了一个小文件(〜500KB),这些步骤将非常有效.但是,如果我上传了较大的文件(5MB-10MB),则会出现以下错误:
These steps work perfectly in case I upload a small file (~500KB).However, if I upload a larger file (5MB-10MB), I get the following error:
Warning: unlink(<Complete Path to File>): Permission denied in <Complete path to uploader.php> on line N
我在Windows上工作,并尝试提升用户对目录和文件的权限. (使用chmod,chown php命令并确保目录可写和可访问)
I am working on Windows and have tried elevating user permissions for the directory and file. (using chmod, chown php commands and made sure that the directory is writable and accessible)
似乎AWS S3 PutObject方法没有释放文件句柄(仅在大文件的情况下).我也尝试过添加sleep()而不是运气.!
It seems that AWS S3 PutObject method is not releasing the file handle (in case of large files only). I have also tried adding sleep() but not luck.!
此外,万一我跳过将文件上传到S3(只是为了测试我的删除工作流程),文件将被删除而没有任何问题.
Moreover, in case I skip uploading the file to S3 (just to test my delete workflow), the file gets deleted without any issue.
请帮助.!
推荐答案
如果其他人也陷入困境,我将nginx服务器部署移至CentOS,但未发现此问题.
In case anybody else is also stuck on this, I moved nginx server deployment to CentOS and this issue was not observed.
这篇关于PHP + S3:使用unlink()删除文件时,权限被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!