脚本宝典收集整理的这篇文章主要介绍了php – 将base64图像上传到amazon s3,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
<?PHP require_once 'classes/amazon.PHP'; require_once 'includes/aws/aws-autoloader.PHP'; use Aws\S3\S3Client; $putdata = file_get_contents("PHP://input"); $request = json_decode($putdata); $image_parts = explode(";base64,",$request->image); $image_tyPE_aux = explode("image/",$image_parts[0]); $image_type = $image_type_aux[1]; $image_base64 = $image_parts[1]; $dateTime = new DateTime(); $fileName = $dateTime->getTimestamp() . "." . $image_type; $s3Client = S3Client::factory(array( 'region' => 'eu-west-1','version' => '2006-03-01','credentials' => array( 'key' => Amazon::getAccessKey(),'secret' => Amazon::getSecretKey(),) )); try { $result = $s3Client->putObject(array( 'Bucket' => Amazon::getBucket(),'Key' => 'banners/' . $fileName,'Body' => $image_base64,'ContentType' => 'image/' . $image_type,'ACL' => 'public-read' )); echo $result['ObjectURL'] . "\n"; } catch(S3Exception $e) { echo $e->getMessage() . "\n"; } ?>
因此,当我在上传图像文件后检查控制台时,它具有预期的大小,权限和标题,但正如我所说,每当我尝试打开文件时,它都会失败.
这可能是什么问题?提前致谢.
以上是脚本宝典为你收集整理的php – 将base64图像上传到amazon s3全部内容,希望文章能够帮你解决php – 将base64图像上传到amazon s3所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。