Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Z
zhichan
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
蒋勇
zhichan
Commits
3a34c282
Commit
3a34c282
authored
Apr 09, 2020
by
王栋源
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wdy
parent
a5eb5402
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
14 deletions
+14
-14
alioss-java/src/main/java/com/example/aliossjava/uploadossapi.java
+4
-3
alioss-java/src/main/java/com/example/aliossjava/utilupload.java
+10
-11
No files found.
alioss-java/src/main/java/com/example/aliossjava/uploadossapi.java
View file @
3a34c282
...
@@ -20,6 +20,7 @@ public class uploadossapi {
...
@@ -20,6 +20,7 @@ public class uploadossapi {
System
.
out
.
println
(
a
);
System
.
out
.
println
(
a
);
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
a
);
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
a
);
String
ossurl
=
jsonObject
.
getString
(
"ossurl"
);
String
ossurl
=
jsonObject
.
getString
(
"ossurl"
);
String
filedir
=
jsonObject
.
getString
(
"filedir"
);
String
objectName
=
jsonObject
.
getString
(
"objectName"
);
String
objectName
=
jsonObject
.
getString
(
"objectName"
);
String
encodePolicy
=
jsonObject
.
getString
(
"encodePolicy"
);
String
encodePolicy
=
jsonObject
.
getString
(
"encodePolicy"
);
String
signature
=
jsonObject
.
getString
(
"signature"
);
String
signature
=
jsonObject
.
getString
(
"signature"
);
...
@@ -27,7 +28,7 @@ public class uploadossapi {
...
@@ -27,7 +28,7 @@ public class uploadossapi {
String
accessKeyId
=
jsonObject
.
getString
(
"accessKeyId"
);
String
accessKeyId
=
jsonObject
.
getString
(
"accessKeyId"
);
String
bucketName
=
jsonObject
.
getString
(
"bucketName"
);
String
bucketName
=
jsonObject
.
getString
(
"bucketName"
);
utilupload
utilupload
=
new
utilupload
();
utilupload
utilupload
=
new
utilupload
();
utilupload
.
doUpload
(
ossurl
,
endpoint
,
accessKeyId
,
bucketName
,
objectName
,
encodePolicy
,
signature
);
utilupload
.
doUpload
(
ossurl
,
endpoint
,
accessKeyId
,
bucketName
,
filedir
,
objectName
,
encodePolicy
,
signature
);
return
true
;
return
true
;
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
return
false
;
return
false
;
...
@@ -41,8 +42,8 @@ public class uploadossapi {
...
@@ -41,8 +42,8 @@ public class uploadossapi {
public
void
helloworlds
(){
public
void
helloworlds
(){
try
{
try
{
System
.
out
.
println
(
"fdfd"
);
System
.
out
.
println
(
"fdfd"
);
testuploadossapi
testuploadossapi
=
new
testuploadossapi
();
//
testuploadossapi testuploadossapi=new testuploadossapi();
testuploadossapi
.
doUpload
();
//
testuploadossapi.doUpload();
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
System
.
err
.
println
(
"Send post request exception: "
+
e
);
System
.
err
.
println
(
"Send post request exception: "
+
e
);
}
}
...
...
alioss-java/src/main/java/com/example/aliossjava/utilupload.java
View file @
3a34c282
...
@@ -17,27 +17,26 @@ import org.apache.commons.io.FileUtils;
...
@@ -17,27 +17,26 @@ import org.apache.commons.io.FileUtils;
public
class
utilupload
{
public
class
utilupload
{
// 上传文件
// 上传文件
private
String
localFilePath
=
""
;
private
String
localFilePath
=
"
/tmp/temporaryfile.jpg
"
;
//
Endpoint以杭州为例,其它Region请按实际情况填写。
//
Endpoint以杭州为例,其它Region请按实际情况填写。
private
String
endpoint
=
"http://oss-cn-beijing.aliyuncs.com"
;
private
String
endpoint
=
"http://oss-cn-beijing.aliyuncs.com"
;
//
阿里云主账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM账号进行API访问或日常运维,请登录 https://ram.console.aliyun.com 创建RAM账号。
//
阿里云主账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM账号进行API访问或日常运维,请登录 https://ram.console.aliyun.com 创建RAM账号。
private
String
accessKeyId
=
"hObpgEXoca42qH3V"
;
private
String
accessKeyId
=
"hObpgEXoca42qH3V"
;
// 存储空间名称
// 存储空间名称
private
String
bucketName
=
"trade-mark-user-upload"
;
private
String
bucketName
=
"trade-mark-user-upload"
;
//
文件名称
//
文件名称
private
String
objectName
=
""
;
private
String
objectName
=
""
;
public
void
doUpload
(
String
ossurl
,
String
endpoint
1
,
String
accessKeyId1
,
String
bucketName1
,
String
objectName
,
String
encodePolicy
,
String
signature
)
throws
Exception
{
public
void
doUpload
(
String
ossurl
,
String
endpoint
,
String
accessKeyId
,
String
bucketName
,
String
filedir
,
String
objectName
,
String
encodePolicy
,
String
signature
)
throws
Exception
{
URL
httpurl
=
new
URL
(
ossurl
);
URL
httpurl
=
new
URL
(
ossurl
);
File
file
=
new
File
(
"
F:\\swch\\commons-io-2.6\\aaa
.jpg"
);
File
file
=
new
File
(
"
/tmp/temporaryfile
.jpg"
);
FileUtils
.
copyURLToFile
(
httpurl
,
file
);
FileUtils
.
copyURLToFile
(
httpurl
,
file
);
this
.
objectName
=
"30039057/icon/1585794705963/"
+
objectName
;
this
.
objectName
=
filedir
+
objectName
;
// this.endpoint=endpoint;
this
.
endpoint
=
endpoint
;
// this.accessKeyId=accessKeyId;
this
.
accessKeyId
=
accessKeyId
;
// this.bucketName=bucketName;
this
.
bucketName
=
bucketName
;
this
.
localFilePath
=
"F:\\swch\\commons-io-2.6\\aaa.jpg"
;
// 在URL中添加存储空间名称,添加后URL如下:http://yourBucketName.oss-cn-hangzhou.aliyuncs.com
// 在URL中添加存储空间名称,添加后URL如下:http://yourBucketName.oss-cn-hangzhou.aliyuncs.com
String
urlStr
=
endpoint
.
replace
(
"http://"
,
"http://"
+
bucketName
+
"."
);
String
urlStr
=
endpoint
.
replace
(
"http://"
,
"http://"
+
bucketName
+
"."
);
// 表单Map。
// 表单Map。
...
...
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