Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
不是太高的手
SPTools
提交
6f221c18
S
SPTools
项目概览
不是太高的手
/
SPTools
通知
4
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
SPTools
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
6f221c18
编写于
9月 08, 2020
作者:
小
小柒2012
提交者:
Gitee
9月 08, 2020
浏览文件
操作
浏览文件
下载
差异文件
优化AliYun OSS日志提示方式
上级
866f2754
db693638
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
24 addition
and
17 deletion
+24
-17
src/main/java/com/tools/module/app/util/AliYunUtils.java
src/main/java/com/tools/module/app/util/AliYunUtils.java
+24
-17
未找到文件。
src/main/java/com/tools/module/app/util/AliYunUtils.java
浏览文件 @
6f221c18
package
com.tools.module.app.util
;
import
com.aliyun.oss.OSS
;
import
com.aliyun.oss.OSSClientBuilder
;
import
java.io.File
;
import
java.io.InputStream
;
import
javax.annotation.PostConstruct
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.stereotype.Component
;
import
javax.annotation.PostConstruct
;
import
java.io.File
;
import
java.io.InputStream
;
import
com.aliyun.oss.OSS
;
import
com.aliyun.oss.OSSClientBuilder
;
/**
* 阿里云存储
*/
@Component
@Configuration
@EnableConfigurationProperties
({
AliYunProperties
.
class
})
@EnableConfigurationProperties
({
AliYunProperties
.
class
})
public
class
AliYunUtils
{
private
final
static
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
AliYunUtils
.
class
);
private
AliYunProperties
aliYun
;
public
AliYunUtils
(
AliYunProperties
aliYun
)
{
this
.
aliYun
=
aliYun
;
this
.
aliYun
=
aliYun
;
}
private
OSS
instance
;
@PostConstruct
public
void
init
()
{
try
{
instance
=
new
OSSClientBuilder
().
build
(
aliYun
.
getEndpoint
(),
aliYun
.
getAccessKeyId
(),
aliYun
.
getAccessKeySecret
());
}
catch
(
Exception
e
)
{
e
.
printStackTrace
(
);
}
try
{
instance
=
new
OSSClientBuilder
().
build
(
aliYun
.
getEndpoint
(),
aliYun
.
getAccessKeyId
(),
aliYun
.
getAccessKeySecret
());
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
"阿里云OSS初始化失败,{}。"
,
e
.
getMessage
()
);
}
}
/**
* 上传
*/
public
void
upload
(
File
file
,
String
fileName
){
instance
.
putObject
(
aliYun
.
getBucketName
(),
fileName
,
file
);
public
void
upload
(
File
file
,
String
fileName
)
{
instance
.
putObject
(
aliYun
.
getBucketName
(),
fileName
,
file
);
}
/**
* 上传
*/
public
void
upload
(
InputStream
file
,
String
fileName
){
instance
.
putObject
(
aliYun
.
getBucketName
(),
fileName
,
file
);
public
void
upload
(
InputStream
file
,
String
fileName
)
{
instance
.
putObject
(
aliYun
.
getBucketName
(),
fileName
,
file
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录