当前位置:网站首页>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;}}}边栏推荐
- 360杜跃进:太空安全风险加剧,需打造一体化防御体系
- Interviewer Ali: Describe to me the phenomenon of cache breakdown, and talk about your solution?
- TensorFlow2:概述
- ELK log analysis system
- How to build FTP server under win2003
- 推荐系统:概述【架构:用户/物品特征工程---->召回层---->排序层---->测试/评估】【冷启动问题、实时性问题】
- Recommendation System - Sorting Layer - Model (1): Embedding + MLP (Multilayer Perceptron) Model [Deep Crossing Model: Classic Embedding + MLP Model Structure]
- 数据库索引:索引并不是万能药
- Apple Silicon配置二进制环境(一)
- coming!Dongfang Selection brings goods to the live broadcast of Longjiang agricultural products
猜你喜欢

基于人脸的常见表情识别(1)——深度学习基础知识

推荐系统-排序层:排序层架构【用户、物品特征处理步骤】

银行数据资产转换能力弱?思迈特软件助力解决银行困境

360杜跃进:太空安全风险加剧,需打造一体化防御体系

对int变量赋值的操作是原子的吗?

How to build FTP server under win2003
![[Node implements data encryption]](/img/8b/f9ff44c39fc9e80b2f2d2626a74076.png)
[Node implements data encryption]

The 17th "Revitalization Cup" National Youth Vocational Skills Competition - Computer Programmers (Cloud Computing Platform and Operation and Maintenance) Participation Review and Summary

MySQL数据库之JDBC编程

MySQL database - DQL data query language
随机推荐
Redisson 的分布式锁找不到?
推荐系统:实时性【特征实时性:客户端实时特征(秒级,实时)、流处理平台(分钟级,近实时)、分布式批处理平台(小时/天级,非实时)】【模型实时性:在线学习、增量更新、全量更新】
基于人脸的常见表情识别(1)——深度学习基础知识
SQLyog注释 添加 撤销 快捷键
Can't find the distributed lock of Redisson?
ERROR 1045 (28000) Access denied for user ‘root‘@‘localhost‘解决方法
【请教】SQL语句按列1去重来计算列2之和?
MySQL分组后取最大一条数据【最优解】
[PM only] Quickly count who else in the team has not registered and reported information, and quickly screen out the members of their own project team who have not completed the list of XXX work items
从离线到实时对客,湖仓一体释放全量数据价值
PHP低代码开发平台 V5.0.7新版发布
Swift简介
ELK log analysis system
【视频】极值理论EVT与R语言应用:GPD模型火灾损失分布分析
el-input 只能输入整数(包括正数、负数、0)或者只能输入整数(包括正数、负数、0)和小数
MySQL database - DQL data query language
明解C语言第六章习题
PostgreSQL 14.4如何安装使用
MySQL夺命10问,你能坚持到第几问?
Recommender systems: overview of the characteristics of architecture: user/item engineering -- -- -- -- -- -- -- -- > recall layer > sort layer - > test/evaluation 】 【 cold start problems, real-time 】