Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
8
8timerapiv200
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
8timerv2
8timerapiv200
Commits
45d8d006
Commit
45d8d006
authored
Mar 20, 2020
by
邓实川
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
测试删除Test包文件
parent
742f4676
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
0 additions
and
189 deletions
+0
-189
src/test/java/cn/timer/api/ApplicationTests.java
+0
-24
src/test/java/cn/timer/api/OSSClientConstants.java
+0
-30
src/test/java/cn/timer/api/OSSTest.java
+0
-135
No files found.
src/test/java/cn/timer/api/ApplicationTests.java
deleted
100644 → 0
View file @
742f4676
package
cn
.
timer
.
api
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
cn.hutool.core.util.ArrayUtil
;
import
cn.hutool.core.util.StrUtil
;
@RunWith
(
SpringRunner
.
class
)
@SpringBootTest
public
class
ApplicationTests
{
@Test
public
void
contextLoads
()
{
}
/*
* public static void main(String[] args) { int[] ints = {1,6,6}; ints = null;
* String str = null; System.err.println(ArrayUtil.join(ints,","));
* System.err.println(StrUtil.splitToInt(str, ",")); }
*/
}
src/test/java/cn/timer/api/OSSClientConstants.java
deleted
100644 → 0
View file @
742f4676
package
cn
.
timer
.
api
;
/**
* @class:OSSClientConstants
* @descript:阿里云注册用户基本常量
* @date 2019-11-21
* @author dsc
*/
public
class
OSSClientConstants
{
//阿里云API的外网域名( 华南/深圳)
public
static
final
String
ENDPOINT
=
"http://oss-cn-shenzhen.aliyuncs.com"
;
//阿里云API的密钥Access Key ID
public
static
final
String
ACCESS_KEY_ID
=
"LTAI4FjnqT1g5SChE5hacic2"
;
//阿里云API的密钥Access Key Secret
public
static
final
String
ACCESS_KEY_SECRET
=
"6b54EvxzM1hE8eGo1bPu8wdRa8zAkm"
;
//阿里云API的bucket名称
public
static
final
String
BACKET_NAME
=
"8time"
;
//阿里云API的文件夹名称
public
static
final
String
FOLDER
=
"8timeV2.0/"
;
}
src/test/java/cn/timer/api/OSSTest.java
deleted
100644 → 0
View file @
742f4676
package
cn
.
timer
.
api
;
import
java.io.File
;
import
com.aliyun.oss.OSS
;
import
com.aliyun.oss.OSSClientBuilder
;
import
com.aliyun.oss.internal.OSSHeaders
;
import
com.aliyun.oss.model.CannedAccessControlList
;
import
com.aliyun.oss.model.GetObjectRequest
;
import
com.aliyun.oss.model.ObjectMetadata
;
import
com.aliyun.oss.model.PutObjectRequest
;
import
com.aliyun.oss.model.StorageClass
;
import
cn.timer.api.utils.Result
;
import
cn.timer.api.utils.ResultUtil
;
/**
* OSS接口操作示例
* 1.创建空间
* 2.上传文件
* 3.下载文件
* @author dsc
*
*/
public
class
OSSTest
{
/**
* 1.创建储存空间
* sout控制台輸出 储存空间名
*/
public
static
Result
<
Void
>
createZone
(
String
bucketName
)
{
// Endpoint以杭州为例,其它Region请按实际情况填写。
String
endpoint
=
"http://oss-cn-shenzhen.aliyuncs.com"
;
// 阿里云主账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM账号进行API访问或日常运维,请登录 https://ram.console.aliyun.com 创建RAM账号。
String
accessKeyId
=
"LTAI4FjnqT1g5SChE5hacic2"
;
String
accessKeySecret
=
"6b54EvxzM1hE8eGo1bPu8wdRa8zAkm"
;
// 创建OSSClient实例。
OSS
ossClient
=
new
OSSClientBuilder
().
build
(
endpoint
,
accessKeyId
,
accessKeySecret
);
// 创建存储空间。
ossClient
.
createBucket
(
bucketName
);
// 关闭OSSClient。
ossClient
.
shutdown
();
// 控制台输出空间名
System
.
err
.
println
(
"bucketName:"
+
bucketName
);
// 返回成功
return
ResultUtil
.
success
();
}
/**
* 2.上传文件
* @param dir 模块文件夹名
* @param fileName 文件名
* @param path 本地文件路径
* @param orgCode 公司id
* @param moudle
* @return 文件名
*/
public
static
Result
<
String
>
uploadFile
(
String
orgCode
,
String
moudle
,
String
dir
,
String
fileName
,
String
path
)
{
// Endpoint以杭州为例,其它Region请按实际情况填写。
String
endpoint
=
"http://oss-cn-shenzhen.aliyuncs.com"
;
// 阿里云主账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM账号进行API访问或日常运维,请登录 https://ram.console.aliyun.com 创建RAM账号。
String
accessKeyId
=
"LTAI4FjnqT1g5SChE5hacic2"
;
String
accessKeySecret
=
"6b54EvxzM1hE8eGo1bPu8wdRa8zAkm"
;
// 上传储存空间设置为8time
String
bucketName
=
"8time"
;
// <yourObjectName>上传文件到OSS时需要指定包含文件后缀在内的完整路径,例如abc/efg/123.jpg。
// String objectName = "8time/test/123.jpg";
// 创建OSSClient实例。
OSS
ossClient
=
new
OSSClientBuilder
().
build
(
endpoint
,
accessKeyId
,
accessKeySecret
);
// 创建PutObjectRequest对象。
// 项目名+用户公司id+模块名+文件夹名+文件名
PutObjectRequest
putObjectRequest
=
new
PutObjectRequest
(
bucketName
,
"8timeV2.0/"
+
orgCode
+
"/"
+
moudle
+
"/"
+
dir
+
"/"
+
fileName
,
new
File
(
path
));
// 如果需要上传时设置存储类型与访问权限,请参考以下示例代码。
// TODO 文件类型jpg jpeg
ObjectMetadata
metadata
=
new
ObjectMetadata
();
metadata
.
setHeader
(
OSSHeaders
.
OSS_STORAGE_CLASS
,
StorageClass
.
Standard
.
toString
());
metadata
.
setObjectAcl
(
CannedAccessControlList
.
Private
);
putObjectRequest
.
setMetadata
(
metadata
);
// 上传文件。
ossClient
.
putObject
(
putObjectRequest
);
// 关闭OSSClient。
ossClient
.
shutdown
();
// 返回上传成功的文件名
return
ResultUtil
.
success
(
fileName
);
}
/**
* 3.从OSS下载文件
* @param objectName 完整路径的文件名
* @param path 本地储存文件路径
* @param orgCode 公司id
* @param dir 包名
* @param fileName 文件名
* @param moudle 模块名
* @return 完整文件名
*/
public
static
Result
<
String
>
downloadFile
(
String
orgCode
,
String
moudle
,
String
dir
,
String
fileName
,
String
path
)
{
// Endpoint以杭州为例,其它Region请按实际情况填写。
String
endpoint
=
"http://oss-cn-shenzhen.aliyuncs.com"
;
// 阿里云主账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM账号进行API访问或日常运维,请登录 https://ram.console.aliyun.com 创建RAM账号。
String
accessKeyId
=
"LTAI4FjnqT1g5SChE5hacic2"
;
String
accessKeySecret
=
"6b54EvxzM1hE8eGo1bPu8wdRa8zAkm"
;
// 下载储存空间设置为8time
String
bucketName
=
"8time"
;
// <yourObjectName>从OSS下载文件时需要指定包含文件后缀在内的完整路径,例如abc/efg/123.jpg。
// String objectName = "8time/test/123.jpg";
// 创建OSSClient实例。
OSS
ossClient
=
new
OSSClientBuilder
().
build
(
endpoint
,
accessKeyId
,
accessKeySecret
);
// 下载OSS文件到本地文件。如果指定的本地文件存在会覆盖,不存在则新建。
ossClient
.
getObject
(
new
GetObjectRequest
(
bucketName
,
"8timeV2.0/"
+
orgCode
+
"/"
+
moudle
+
"/"
+
dir
+
"/"
+
fileName
),
new
File
(
path
+
fileName
));
// 关闭OSSClient。
ossClient
.
shutdown
();
// 完整路径的文件名
System
.
err
.
println
(
"objectName:"
+
"8timeV2.0/"
+
orgCode
+
"/"
+
moudle
+
"/"
+
dir
+
"/"
+
fileName
);
System
.
err
.
println
(
"path:"
+
path
+
fileName
);
// 返回成功的本地路径
return
ResultUtil
.
success
(
path
+
fileName
);
}
//测试
public
static
void
main
(
String
[]
args
)
{
// OSSTest oTest = new OSSTest();
// oTest.createZone();
// oTest.uploadFile("123456", "模块名", "123.jpg", new File("C:\\Users\\Administrator\\Pictures\\Saved Pictures\\1.jpg"));
// oTest.downloadFile("123456", "模块名", "123.jpg", "C:\\Users\\Administrator\\Desktop\\");
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment