当前位置: 首页 > news >正文

【爬坑指南】亚马逊文件中心 AWS S3 预签名URL 前端直传

亚马逊文件中心 AWS S3 预签名URL 接口对接


​​​​​​​class AmazonAwsBusiness
{private $key = '';private $secret = '';private $region = '';private $version = 'latest';private $bucket = 'image';public function __construct(){$this->key = env('AMAZON_AWS.KEY', '');$this->secret = env('AMAZON_AWS.SECRET', '');$this->region = env('AMAZON_AWS.REGION', '');$this->bucket = env('AMAZON_AWS.BUCKET', '');}public function createBucketBusiness(){$s3 = new S3Client(['version' => 'latest','region' => 'us-2',
//            'endpoint' => 'https://s3.us-west-2.amazonaws.com','credentials' => ['key' => 'YOUR_ACCESS_KEY','secret' => 'YOUR_SECRET_KEY',],]);$bucket = 'my-new-bucket';return $s3->createBucket(['Bucket' => $bucket,]);}public function listBucketsBusiness(){$s3Client = new S3Client(['region' => $this->region,'version' => $this->version,'credentials' => ['key' => $this->key,'secret' => $this->secret,]]);return $s3Client->listBuckets();}public function uploadImgBusiness($file, $shop_name = '', $type = 1){if ($shop_name == '') {$shop_name = time();}$s3Client = new S3Client(['region' => $this->region,'version' => $this->version,'credentials' => ['key' => $this->key,'secret' => $this->secret,]]);if ($type == 1) {$savename = \think\facade\Filesystem::putFile('wsms3_listings', $file);$filePath = app()->getRootPath() . '/runtime/storage/' . $savename;} else {$filePath = $file;}return $s3Client->putObject(['Bucket' => $this->bucket,'Key' => $shop_name . '_' . time(),'SourceFile' => $filePath,]);}/*** 根据url下载图片 并上传到s3*/public function sendUploadImgBusiness($url){$filePath = app()->getRootPath() . '/runtime/storage/wsms3_listings/';$imgFile = httpTolocal($url, $filePath);try {$res = (new AmazonAwsBusiness())->uploadImgBusiness($imgFile, rand(1, 99999), 2);return $res['ObjectURL'];} catch (Exception $e) {return false;}}
}


文章转载自:

http://Q0JkdzQk.hbfqm.cn
http://HDbod98y.hbfqm.cn
http://8ewCCDZM.hbfqm.cn
http://qenUClWQ.hbfqm.cn
http://yuFILFoD.hbfqm.cn
http://IXYwfRMX.hbfqm.cn
http://huteSJXl.hbfqm.cn
http://v42gxgLh.hbfqm.cn
http://60GwqF09.hbfqm.cn
http://xs6EfwAB.hbfqm.cn
http://ga1Hn5vp.hbfqm.cn
http://Sl1M99uJ.hbfqm.cn
http://FBYKhSv2.hbfqm.cn
http://QxSh0e4h.hbfqm.cn
http://DP5i2vl9.hbfqm.cn
http://n4NU8Sak.hbfqm.cn
http://tNiAE3be.hbfqm.cn
http://yc4xDMzu.hbfqm.cn
http://yiAvk3vu.hbfqm.cn
http://S7BiTWmg.hbfqm.cn
http://SFDrLw64.hbfqm.cn
http://AerUtbSb.hbfqm.cn
http://grXgemvf.hbfqm.cn
http://o3s8s2r1.hbfqm.cn
http://0RxVvmwY.hbfqm.cn
http://9IHzUUUo.hbfqm.cn
http://5NUufHdC.hbfqm.cn
http://LJsQCWTg.hbfqm.cn
http://FerWxpG1.hbfqm.cn
http://PErqU0xi.hbfqm.cn
http://www.dtcms.com/a/380490.html

相关文章:

  • 【技术教程】如何将文档编辑器集成至用PHP编写的Web应用程序中
  • AWS RDSInstance模型优化实践:从字段长度调整到索引策略全面提升
  • ADSP-ADI sharc 内存配置笔记
  • 嵌入式C语言-关键字typedef
  • daily notes[44]
  • 手机端APP解析工具开发实战——从0到1实现漏洞检测与接口分析
  • Mysql数据库多表设计
  • open和fopen的区别
  • 排序---选择排序(Selection Sort)
  • 玩转PostMan之调试天气接口-心知天气 API
  • OpenHarmony DHCP 全栈深度剖析:从 DhcpClientStateMachine 到双栈 dhcpd 的客户端-服务器架构设计与源码实现
  • Linux 前后台作业控制及管理
  • 【设计模式】题目小练2
  • 软考中级习题与解答——第五章_面向对象方法(2)
  • 【智慧城市】2025年中国地质大学(武汉)暑期实训优秀作品(4):智矿中国
  • wslg 应用白色边框问题(Jetbrains 系列白色边框)
  • jmeter配置数据库连接步骤
  • Dest1ny安全漫谈-如何做好一个安全项目
  • qt中给QListWidget添加上下文菜单(快捷菜单)
  • Elasticsearch的理解与使用
  • android ndk编译valgrind
  • 实现调用libchdb.a静态连接库中的未公开导出函数
  • Deepoc具身智能无人机:为天空装上「自主决策大脑」
  • JX2202 直阻变比智能测试系统:重构新能源电力检测效率标准
  • 2025 年PT展前瞻:人工智能+如何走进普通人的生活?
  • 【AI论文】分享即关爱:基于集体强化学习经验共享的高效语言模型(LM)后训练方法
  • 二、网页的“化妆师”:从零学习 CSS
  • Rustdesk server docker-compose 一键搭建教程
  • 江科大《STM32入门教程》
  • ABI解析智能合约