FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
java-sdk/examples/QvmUploadDemo.java at master · CDNCloud-com/java-sdk · GitHub
CDNCloud-com
/
java-sdk
Public
forked from
qiniu/java-sdk
Notifications
You must be signed in to change notification settings
Fork
0
Star
1
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
java-sdk
/
examples
/
QvmUploadDemo.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
45 lines (43 loc) · 1.93 KB
Breadcrumbs
java-sdk
/
examples
/
QvmUploadDemo.java
Copy path
File metadata and controls
45 lines (43 loc) · 1.93 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package
com
.
qiniu
.
storage
;
import
com
.
qiniu
.
common
.
Zone
;
import
com
.
qiniu
.
http
.
Response
;
import
com
.
qiniu
.
storage
.
Configuration
;
import
com
.
qiniu
.
storage
.
UploadManager
;
import
com
.
qiniu
.
util
.
Auth
;
/**
* 华东 1 区域(杭州)和华北 2 区域(北京)的云主机 通过内网上传资源到七牛同区域的对象存储空间,
* 并且避免绕行公网带来的网络质量不稳定问题,也可以免去数据在传输过程中被窃取的风险,
* 参考文档:https://developer.qiniu.com/qvm/manual/4269/qvm-kodo
*/
public
class
QvmUploadDemo
{
// 获取凭证
public
static
void
main
(
String
[]
args
) {
//设置账号的AK,SK
String
ACCESS_KEY
=
"Access_Key"
;
String
SECRET_KEY
=
"Secret_Key"
;
//要上传的空间
String
bucketname
=
"Bucket_Name"
;
//上传到七牛后保存的文件名
String
key
=
"my-java.png"
;
//上传文件的路径
String
FilePath
=
"/.../..."
;
// 构造一个带指定的zone对象的配置类,华东1区域的云主机可以选择Zone.qvmZone0(),华北2区域(北京)的云主机可以选择Zone.qvmZone1(),目前其他存储区域是不支持
Configuration
configuration
=
new
Configuration
(
Zone
.
qvmZone0
());
//创建上传对象
UploadManager
uploadManager
=
new
UploadManager
(
configuration
);
//秘钥鉴权
Auth
auth
=
Auth
.
create
(
ACCESS_KEY
,
SECRET_KEY
);
//简单上传,使用默认策略,只需要设置上传的空间名就可以了
String
upToken
=
auth
.
uploadToken
(
bucketname
);
Response
res
=
null
;
try
{
//调用上传方法
res
=
uploadManager
.
put
(
FilePath
,
key
,
upToken
);
}
catch
(
QiniuException
e
) {
e
.
printStackTrace
();
}
//打印返回的信息
System
.
out
.
println
(
res
.
statusCode
);
System
.
out
.
println
(
res
.
toString
());
}
}
Back
|
FazBrowse Home
|
New Git URL