当前位置:网站首页>阿里云对象存储oss私有桶生成链接
阿里云对象存储oss私有桶生成链接
2022-08-03 04:55:00 【无名之辈之码谷娃】
业务场景:
1,需要别的平台下载文件上传到oss对象存储。
2,app端需要小图缩略图显示,包括视频截帧。
3,安全访问和内存调节等。
4,聊天平台转换等。
对象存储帮我们存储文件,数据,更安全,更快捷。
阿里云oss地址:
我们通过私有桶加密的方式使用链接转换,根据时间生成有效链接。
/**
* 通过上传获取到 验签的文件url地址
*
* @param ossClient
* @param key
* @return
*/
public static String getFileUrl(OSS ossClient, String key,String bucketName) throws ParseException {
Date date = new Date();
Calendar cal = Calendar.getInstance();
cal.setTime(date);
//增加一年
cal.add(Calendar.YEAR, 1);
GeneratePresignedUrlRequest generatePresignedUrlRequest;
generatePresignedUrlRequest = new GeneratePresignedUrlRequest(bucketName, key);
generatePresignedUrlRequest.setExpiration(cal.getTime());
URL url = ossClient.generatePresignedUrl(generatePresignedUrlRequest);
return url.toString();
}图片缩略和视频缩略
GeneratePresignedUrlRequest generatePresignedUrlRequest;
generatePresignedUrlRequest = new GeneratePresignedUrlRequest(bucketName, key);
generatePresignedUrlRequest = new GeneratePresignedUrlRequest(bucketName, key);
generatePresignedUrlRequest.setExpiration(cal.getTime());
generatePresignedUrlRequest.setProcess(wechatConfig.getLargerImgStyle());
URL largerImgUrl = ossClient.generatePresignedUrl(generatePresignedUrlRequest);
#大图缩略
larger_img_style: image/resize,l_720
#小图缩略
thumbnail_img_style: image/resize,l_198
#视频缩略
video_style: video/snapshot,t_50000,f_jpg,w_800,h_600
//视频缩略
// 创建OSSClient实例。
GeneratePresignedUrlRequest req = new GeneratePresignedUrlRequest(bucketName, key, HttpMethod.GET);
req.setExpiration(cal.getTime());
req.setProcess(wechatConfig.getVideoStyle());
URL signedUrl = ossClient.generatePresignedUrl(req);我们通过setProcess 设置熟悉即可,阿里云官网也有详细的参考和教程。


边栏推荐
- 2022 Henan Mengxin League Game (4): Zhengzhou University of Light Industry E - Sleep Well
- 接口测试如何准备测试数据
- Redis缓存雪崩、缓存穿透、缓存击穿
- Two ways to simulate multi-user login in Jmeter
- Tributyl-mercaptophosphane "tBuBrettPhos Pd(allyl)" OTf), 1798782-17-8
- Where is the value of testers
- BIOTIN ALKYNE CAS: 773888-45-2 Price, Supplier
- Common lipophilic cell membrane dyes DiO, Dil, DiR, Did spectrograms and experimental procedures
- Harmony OS ets ArkUI 】 【 】 the development basic page layout and data connection
- OSI的分层特点、传输过程与三次握手、四次挥手、tcp与udp包头的描述
猜你喜欢

打破传统电商格局,新型社交电商到底有什么优点?

【HMS core】【Ads Kit】华为广告——海外应用在国内测试正式广告无法展示

GIS数据漫谈(五)— 地理坐标系统

How to use the interface management tool YApi?Beautiful, easy to manage, super easy to use

社交电商:流量红利已尽,裂变营销是最低成本的获客之道

Online password generator tool recommendation

Shell之条件语句

Harmony OS ets ArkUI 】 【 】 the development basic page layout and data connection

【Harmony OS】【FAQ】鸿蒙问题合集1

超好用的画图工具推荐
随机推荐
User password encryption tool
12.机器学习基础:评估机器学习模型
[Developers must see] [push kit] Collection of typical problems of push service service 2
Interface test Mock combat (2) | Combined with jq to complete batch manual Mock
Technology Sharing | How to do assertion verification for xml format in interface automation testing?
typescript44-对象之间的类兼容器
移动流量的爆发式增长,社交电商如何选择商业模式
unity2D横板游戏教程6-敌人AI以及受击动画
[Fine talk] Using native js to implement todolist
Talking about GIS Data (6) - Projected Coordinate System
Redis连接不上的报错解决方案汇总
接口测试框架实战(一) | Requests 与接口请求构造
表的创建、修改与删除
rosbag工具plotjuggler无法打开rosbag的问题
WinForm的控件二次开发
CAD有生僻字如何打出来、如何提交软件相关问题或建议?
【Harmony OS】【ARK UI】Date 基本操作
11.机器学习基础:机器学习的四个分支
【开发者必看】【push kit】推送服务服务典型问题合集2
Redis缓存雪崩、缓存穿透、缓存击穿