我已经安装了适用于 php 的 amazon aws SDK。我正在尝试将文件从服务器上传到 s3 存储桶中。这是当前的流程,用户上传图片,我们保存它,然后运行裁剪脚本。然后我们将图像全部裁剪并准备好保存在我们的 ec2 实例上。然后我想将此文件传输到 s3 存储桶,以便我可以从服务器中删除它。我的问题是上传过程“有效”,但上传的所有文件大小均为 20-50 字节。下面是我的代码
$s3 = App::make('aws')->get('s3');
$s3->putObject(array(
'Bucket' => 'images',
'ACL' => 'public-read',
'Key' => '/avatars/myImage.jpg',
'ContentType' => 'image/jpeg',
'Body' => $imgUrl
));
这会在我的亚马逊 s3 存储桶上创建一个具有正确类型、位置和权限的文件。但文件总是 20-50 字节,也就是空的。知道是什么原因造成的吗? $imgUrl 是文件的路径。
最佳答案
试试这个:'Body' => fopen($pathToFile, 'r+')
Pass a string containing the body, a handle returned by fopen, or a Guzzle\Http\EntityBodyInterface object
关于php - Amazon S3 存储桶上传所有文件为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25893372/