当前位置:网站首页>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 watching "Second Uncle", I was even more internalized
- Maxwell 一款简单易上手的实时抓取Mysql数据的软件
- 基于人脸的常见表情识别(1)——深度学习基础知识
- ELK日志分析系统
- Linux download and install mysql5.7 version tutorial the most complete and detailed explanation
- Redisson 的分布式锁找不到?
- LeetCode 0952. Calculate Maximum Component Size by Common Factor: Mapping / Union Search
- Centos7 install mysql8
- 历史上的今天:Win10 七周年;微软和雅虎的搜索协议;微软发行 NT 4.0
- MySQL sub-database sub-table
猜你喜欢

ELK log analysis system

网络层协议------IP协议

The 17th "Revitalization Cup" National Youth Vocational Skills Competition - Computer Programmers (Cloud Computing Platform and Operation and Maintenance) Participation Review and Summary
Typora设置标题自动标号

Cesium loads offline maps and offline terrain

多线程的互斥锁应用RAII机制
Database Tuning - Database Tuning
![Recommended system: cold start problem [user cold start, item cold start, system cold start]](/img/e1/c3f8c89616d63cd3af84e715e783f9.png)
Recommended system: cold start problem [user cold start, item cold start, system cold start]

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

普通的int main(){}没有写return 0;会怎么样?
随机推荐
Different lower_case_table_names settings for server (‘1‘) and data dictionary (‘0‘) 解决方案
明解C语言第五章习题
JUnit 5测试中的临时目录(附实例及代码)
After watching "Second Uncle", I was even more internalized
Interviewer Ali: Describe to me the phenomenon of cache breakdown, and talk about your solution?
MySQL database - views and indexes
ImportError: attempted relative import with no known parent package
DCM 中间件家族迎来新成员
centos7安装mysql8
推荐系统:AB测试(AB Test)
MySQL函数(经典收藏)
The technology is very powerful, do you still need to "manage up"?
Scala类中的属性
MySQL复制表结构、表数据的方法
Database Tuning - Database Tuning
Apple Silicon配置二进制环境(一)
我是一名阿里在职9年软件测试工程师,我的经历也许能帮到处于迷茫期的你
Linux下载安装mysql5.7版本教程最全详解
MySQL slow query optimization
Recommendation system: evaluation index [offline evaluation index: RMSE (root mean square error), AUC, precision, recall, F1] [online evaluation: A/B test] [generally required response time <0.5s]