我有一个脚本,可以调整和裁剪图像,并希望能够即时将图像上传到我的Amazon S3。但是,当我尝试运行脚本时,出现了错误信息,我猜测是因为源文件($filepath)不被识别为直接从磁盘中获取的路径。你有什么想法来解决这个问题吗?
以下是错误信息: 致命错误:未捕获异常 'Aws\Common\Exception\InvalidArgumentException',错误消息为 ' 您必须为Body或SourceFile参数指定非空值。' in phar:///var/www/submit/aws.phar/Aws/Common/Client/UploadBodyListener.php:...
以下是错误信息: 致命错误:未捕获异常 'Aws\Common\Exception\InvalidArgumentException',错误消息为 ' 您必须为Body或SourceFile参数指定非空值。' in phar:///var/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";
}