55import cn .hellohao .pojo .ReturnImage ;
66import com .google .gson .Gson ;
77import com .qiniu .common .QiniuException ;
8- import com .qiniu .common .Zone ;
98import com .qiniu .http .Response ;
109import com .qiniu .storage .BucketManager ;
1110import com .qiniu .storage .Configuration ;
11+ import com .qiniu .storage .Region ;
1212import com .qiniu .storage .UploadManager ;
1313import com .qiniu .storage .model .DefaultPutRet ;
1414import com .qiniu .storage .model .FileInfo ;
@@ -28,18 +28,7 @@ public class KODOImageupload {
2828 public ReturnImage ImageuploadKODO (
2929 Map <Map <String , String >, File > fileMap , String username , Integer keyID ) {
3030 ReturnImage returnImage = new ReturnImage ();
31- Configuration cfg ;
32- if (key .getEndpoint ().equals ("1" )) {
33- cfg = new Configuration (Zone .zone0 ());
34- } else if (key .getEndpoint ().equals ("2" )) {
35- cfg = new Configuration (Zone .zone1 ());
36- } else if (key .getEndpoint ().equals ("3" )) {
37- cfg = new Configuration (Zone .zone2 ());
38- } else if (key .getEndpoint ().equals ("4" )) {
39- cfg = new Configuration (Zone .zoneNa0 ());
40- } else {
41- cfg = new Configuration (Zone .zoneAs0 ());
42- }
31+ Configuration cfg = new Configuration (Region .autoRegion ());
4332 UploadManager uploadManager = new UploadManager (cfg );
4433 Auth auth = Auth .create (key .getAccessKey (), key .getAccessSecret ());
4534 String upToken = auth .uploadToken (key .getBucketname (), null , 7200 , null );
@@ -76,41 +65,25 @@ public ReturnImage ImageuploadKODO(
7665
7766 public static Integer Initialize (Keys k ) {
7867 int ret = -1 ;
79- if (org . apache . commons . lang3 . StringUtils .isBlank (k .getAccessKey ())
80- || org . apache . commons . lang3 . StringUtils .isBlank (k .getAccessSecret ())
81- || org . apache . commons . lang3 . StringUtils .isBlank (k .getEndpoint ())
82- || org . apache . commons . lang3 . StringUtils .isBlank (k .getBucketname ())
68+ if (StringUtils .isBlank (k .getAccessKey ())
69+ || StringUtils .isBlank (k .getAccessSecret ())
70+ || StringUtils .isBlank (k .getEndpoint ())
71+ || StringUtils .isBlank (k .getBucketname ())
8372 || StringUtils .isBlank (k .getRequestAddress ())) {
8473 return -1 ;
8574 }
86- Configuration cfg ;
87- if (k .getEndpoint ().equals ("1" )) {
88- cfg = new Configuration (Zone .zone0 ());
89- } else if (k .getEndpoint ().equals ("2" )) {
90- cfg = new Configuration (Zone .zone1 ());
91- } else if (k .getEndpoint ().equals ("3" )) {
92- cfg = new Configuration (Zone .zone2 ());
93- } else if (k .getEndpoint ().equals ("4" )) {
94- cfg = new Configuration (Zone .zoneNa0 ());
95- } else {
96- cfg = new Configuration (Zone .zoneAs0 ());
97- }
75+ Configuration cfg = new Configuration (Region .autoRegion ());
9876 UploadManager uploadManager = new UploadManager (cfg );
9977 Auth auth = Auth .create (k .getAccessKey (), k .getAccessSecret ());
100- String upToken =
101- auth .uploadToken (
102- k .getBucketname (),
103- null ,
104- 7200 ,
105- null ); // auth.uploadToken(k.getBucketname());
106- BucketManager bmObj = new BucketManager (auth , cfg );
78+ String upToken = auth .uploadToken (k .getBucketname (), null , 7200 , null );
79+ BucketManager BM = new BucketManager (auth , cfg );
10780 BucketManager .FileListIterator fileListIterator = null ;
10881 try {
109- fileListIterator = bmObj .createFileListIterator (k .getBucketname (), "" , 1 , "/" );
82+ fileListIterator = BM .createFileListIterator (k .getBucketname (), "" , 1 , "/" );
11083 FileInfo [] items = fileListIterator .next ();
11184 if (items != null ) {
11285 ret = 1 ;
113- bucketManager = bmObj ;
86+ bucketManager = BM ;
11487 key = k ;
11588 }
11689 } catch (Exception e ) {
0 commit comments