【发布时间】:2014-05-19 00:12:05
【问题描述】:
我有一个脚本可以调整图像大小和裁剪图像,我想将图像上传到我的亚马逊 S3 上。
问题是当我尝试运行我的脚本时收到一条错误消息,因为我猜源文件未被识别为来自磁盘的直接路径 ($filepath)。你有什么办法度过这个难关吗?
致命错误:在 phar:///var 中未捕获异常“Aws\Common\Exception\InvalidArgumentException”和消息“您必须为 Body 或 SourceFile 参数指定非空值。” /www/submit/aws.phar/Aws/Common/Client/UploadBodyListener.php:...
$myResizedImage = imagecreatetruecolor($width,$height);
imagecopyresampled($myResizedImage,$myImage,0,0,0,0, $width, $height, $origineWidth, $origineHeight);
$myImageCrop = imagecreatetruecolor(612,612);
imagecopy( $myImageCrop, $myResizedImage, 0,0, $posX, $posY, 612, 612);
//Save image on Amazon S3
require 'aws.phar';
use Aws\S3\S3Client;
use Aws\S3\Exception\S3Exception;
$bucket = 'yol';
$keyname = 'image_resized';
$filepath = $myImageCrop;
// Instantiate the client.
$s3 = S3Client::factory(array(
'key' => 'private-key',
'secret' => 'secrete-key',
'region' => 'eu-west-1'
));
try {
// Upload data.
$result = $s3->putObject(array(
'Bucket' => $bucket,
'Key' => $keyname,
'SourceFile' => $filepath,
'ACL' => 'public-read',
'ContentType' => 'image/jpeg'
));
// Print the URL to the object.
echo $result['ObjectURL'] . "\n";
} catch (S3Exception $e) {
echo $e->getMessage() . "\n";
}
【问题讨论】:
-
你能发布完整的代码吗?我也遇到了同样的错误。
标签: php file-upload amazon-web-services amazon-s3