引入依赖
Hntool对所有第三方都是可选依赖,因此在使用腾讯云存储时需要自行引入第三方依赖。
<!--腾讯云上传相关依赖--><dependency><groupId>com.qcloud</groupId><artifactId>cos_api</artifactId><version>5.6.15</version></dependency>
获取临时授权码
<!--腾讯云上传获取临时授权码需要--><dependency><groupId>com.tencent.cloud</groupId><artifactId>cos-sts-java</artifactId><version>3.0.6</version></dependency>
腾讯云文档地址
参数
在配置表中,配置以下参数:
| 名称 | 配置名 | 配置值 |
|---|---|---|
| 【腾讯云存储】secretId | upload.tencent.secretId | xxxxx |
| 【腾讯云存储】secretKey | upload.tencent.secretKey | xxxxx |
| 【腾讯云存储】region | upload.tencent.region | xxxxx |
| 【腾讯云存储】bucket | upload.tencent.bucket | xxxxx |
| 【腾讯云存储】fileUrl | upload.tencent.fileUrl | https://xxxx |
申请密钥
调用工具类插入参数
TencentUpload.Param param = TencentUpload.createParam();param.setSecretId("xxxx");param.setSecretKey("xxxx");param.setRegion("xxxx");param.setBucket("xxxx");param.setFileUrl("xxxx");genUtils.uploadTencent(param);
使用
File file = FileUtil.file("C:\\Users\\Administrator\\Pictures\\4.jpg");String targetPath="123456.jpg";FileUploadUtil.uploadFile(UploadPlatform.Tencent,file,targetPath);// 过期时间int expireTime = 30;// 获取临时路径FileUploadUtil.getTempDownUrl(UploadPlatform.Tencent,targetPath,expireTime);

