当前位置:网站首页>阿里云对象存储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 设置熟悉即可,阿里云官网也有详细的参考和教程。


边栏推荐
- Interface Test Framework Practice (4) | Get Schema Assertion
- 链动2+1模式简单,奖励结构丰厚,自主裂变?
- 接口管理工具YApi怎么用?颜值高、易管理、超好用
- 软件开发的最大的区别是什么?
- 【Harmony OS】【ArkUI】ets开发 图形与动画绘制
- typescript42-readonly修饰符
- 测试人员的价值体现在哪里
- typescript46-函数之间的类型兼容性
- 【Harmony OS】【ARK UI】ets使用startAbility或startAbilityForResult方式调起Ability
- Where is the value of testers
猜你喜欢

【Harmony OS】【ArkUI】ets开发 图形与动画绘制

Shell之条件语句

Windows 安装PostgreSQL

CobalStrike(CS)基础超级详细版

Common lipophilic cell membrane dyes DiO, Dil, DiR, Did spectrograms and experimental procedures

WinForm的控件二次开发

CAD有生僻字如何打出来、如何提交软件相关问题或建议?

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

荧光标记多肽FITC/AMC/FAM/Rhodamine/TAMRA/Cy3/Cy5/Cy7-Peptide

Kotlin-Flow common encapsulation class: the use of StateFlow
随机推荐
Common fluorescent dyes to modify a variety of groups and its excitation and emission wavelength data in the data
接口和协议
install ambari
测试人员的价值体现在哪里
typescript42-readonly修饰符
Concepts and Methods of Exploratory Testing
【Harmony OS】【FAQ】鸿蒙问题合集1
[Developers must see] [push kit] Collection of typical problems of push service service 2
8.电影评论分类:二分类问题
Unity2D horizontal board game tutorial 6 - enemy AI and attack animation
移动流量的爆发式增长,社交电商如何选择商业模式
Shell conditional statement judgment
Harmony OS ets ArkUI 】 【 】 the development basic page layout and data connection
shell脚本循环语句
Interface test practice | Detailed explanation of the difference between GET / POST requests
3.张量运算
在线密码生成工具推荐
Where is the value of testers
修饰生物素DIAZO-生物素-PEG3-DBCO|重氮-生物素-三聚乙二醇-二苯基环辛炔
三丁基-巯基膦烷「tBuBrettPhos Pd(allyl)」OTf),1798782-17-8