当前位置:网站首页>OSS simply upload pictures
OSS simply upload pictures
2022-07-30 20:03:00 【ldj2020】
package com.atguigu.oss.service.impl;import com.aliyun.oss.OSS;import com.aliyun.oss.OSSClientBuilder;import com.atguigu.oss.service.OssService;import com.atguigu.oss.utils.ConstantPropertiesUtils;import org.joda.time.DateTime;import org.springframework.stereotype.Service;import org.springframework.web.multipart.MultipartFile;import java.io.InputStream;import java.text.SimpleDateFormat;import java.util.Date;import java.util.UUID;@Servicepublic class OssServiceImpl implements OssService {//Upload avatar to [email protected] String uploadFileAvatar(MultipartFile file) {// The constant value obtained by the tool class can also be configured to the configuration file @Value(${xxx}) to obtainString endpoint = ConstantPropertiesUtils.END_POIND;String accessKeyId = ConstantPropertiesUtils.ACCESS_KEY_ID;String accessKeySecret = ConstantPropertiesUtils.ACCESS_KEY_SECRET;String bucketName = ConstantPropertiesUtils.BUCKET_NAME;try {// Create an OSS instance.OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);//Get the upload file input streamInputStream inputStream = file.getInputStream();//get file nameString fileName = file.getOriginalFilename();String uuid = UUID.randomUUID().toString().replaceAll("-", "");fileName = uuid + fileName;String datePath = new DateTime().toString("yyyy/MM/dd");fileName = datePath + "/" + fileName;/*** Call the oss method to upload* The first parameter Bucket name* The second parameter uploads to the oss file path and file name* The third parameter upload file input stream*/ossClient.putObject(bucketName, fileName, inputStream);// Close OSSClient.ossClient.shutdown();//Need to manually splice the oss path uploaded to Alibaba Cloudreturn "https://" + bucketName + "." + endpoint + "/" + fileName;} catch (Exception e) {e.printStackTrace();return null;}}}边栏推荐
- After MySQL grouping, take the largest piece of data [optimal solution]
- MySQL database --- Addition, deletion, modification and query of MySQL tables (advanced)
- Niuke.com - Huawei Question Bank (100~108)
- 【PM专用】快速统计团队还有谁没有登记上报信息,快速筛选出属于自己项目组的成员,未完成XXX工作事项的名单
- 18.客户端会话技术Cookie
- MySQL大总结
- Database indexes: indexes are not a panacea
- 明解C语言第七章习题
- 推荐系统:实时性【特征实时性:客户端实时特征(秒级,实时)、流处理平台(分钟级,近实时)、分布式批处理平台(小时/天级,非实时)】【模型实时性:在线学习、增量更新、全量更新】
- Typora设置标题自动标号
猜你喜欢

基于人脸的常见表情识别(2)——数据获取与整理

MySQL分库分表

如何优化OpenSumi终端性能?

Is the iPhone really thirteen incense?The two generations of products are completely compared, perhaps the previous generation is more worth buying

MySQL六脉神剑,SQL通关大总结

LeetCode 0952. Calculate Maximum Component Size by Common Factor: Mapping / Union Search

PHP低代码开发引擎—表单设计

Maxwell 一款简单易上手的实时抓取Mysql数据的软件
![[PyTorchVideo Tutorial 01] Quickly implement video action recognition](/img/1a/696c5722bb94fabd688a8714ae2e8c.png)
[PyTorchVideo Tutorial 01] Quickly implement video action recognition

ERROR 1045 (28000) Access denied for user 'root'@'localhost'Solution
随机推荐
Common Expression Recognition Based on Face (1) - Basic Knowledge of Deep Learning
Zabbix 5.0 Monitoring Tutorial (1)
halcon——轮廓线
【视频】极值理论EVT与R语言应用:GPD模型火灾损失分布分析
Interviewer Ali: Describe to me the phenomenon of cache breakdown, and talk about your solution?
After MySQL grouping, take the largest piece of data [optimal solution]
Different lower_case_table_names settings for server (‘1‘) and data dictionary (‘0‘) 解决方案
MySQL函数(经典收藏)
FFmpeg —— 将mp4转为gif输出(附源码)
“数字化重构系统,搞定 CEO 是第一步”
Zabbix部署与练习
MySQL数据库 ---MySQL表的增删改查(进阶)
Start background services across processes
Recommended system: cold start problem [user cold start, item cold start, system cold start]
对int变量赋值的操作是原子的吗?
055 c# print
Database indexes: indexes are not a panacea
mysql8 installation under linux
多线程的互斥锁应用RAII机制
Typora设置标题自动标号