55use Qiniu \Region ;
66use Qiniu \Storage \ResumeUploader ;
77use Qiniu \Storage \UploadManager ;
8+ use Qiniu \Http \Client ;
89use Qiniu \Config ;
910use Qiniu \Zone ;
1011
@@ -24,7 +25,7 @@ protected function setUp()
2425
2526 public function test4ML ()
2627 {
27- $ key = ' resumePutFile4ML ' ;
28+ $ key = " resumePutFile4ML_ " . rand () ;
2829 $ upManager = new UploadManager ();
2930 $ token = $ this ->auth ->uploadToken ($ this ->bucketName , $ key );
3031 $ tempFile = qiniuTempFile (4 * 1024 * 1024 + 10 );
@@ -42,12 +43,17 @@ public function test4ML()
4243 $ this ->assertNull ($ error );
4344 $ this ->assertNotNull ($ ret ['hash ' ]);
4445 unlink ($ resumeFile );
46+
47+ $ domain = getenv ('QINIU_TEST_DOMAIN ' );
48+ $ response = Client::get ("http:// $ domain/ $ key " );
49+ $ this ->assertEquals (200 , $ response ->statusCode );
50+ $ this ->assertEquals (md5_file ($ tempFile , true ), md5 ($ response ->body (), true ));
4551 unlink ($ tempFile );
4652 }
4753
4854 public function test4ML2 ()
4955 {
50- $ key = 'resumePutFile4ML ' ;
56+ $ key = 'resumePutFile4ML_ ' . rand () ;
5157 $ zone = new Zone (array ('upload.fake.qiniu.com ' ), array ('upload.qiniup.com ' ));
5258 $ cfg = new Config ($ zone );
5359 $ upManager = new UploadManager ($ cfg );
@@ -67,6 +73,11 @@ public function test4ML2()
6773 $ this ->assertNull ($ error );
6874 $ this ->assertNotNull ($ ret ['hash ' ]);
6975 unlink ($ resumeFile );
76+
77+ $ domain = getenv ('QINIU_TEST_DOMAIN ' );
78+ $ response = Client::get ("http:// $ domain/ $ key " );
79+ $ this ->assertEquals (200 , $ response ->statusCode );
80+ $ this ->assertEquals (md5_file ($ tempFile , true ), md5 ($ response ->body (), true ));
7081 unlink ($ tempFile );
7182 }
7283
@@ -82,13 +93,45 @@ public function test4ML2()
8293 // unlink($tempFile);
8394 // }
8495
96+ public function testResumeUploadWithParams ()
97+ {
98+ $ key = "resumePutFile4ML_ " .rand ();
99+ $ upManager = new UploadManager ();
100+ $ policy = array ('returnBody ' => '{"hash":$(etag),"fname":$(fname),"var_1":$(x:var_1),"var_2":$(x:var_2)} ' );
101+ $ token = $ this ->auth ->uploadToken ($ this ->bucketName , $ key , 3600 , $ policy );
102+ $ tempFile = qiniuTempFile (4 * 1024 * 1024 + 10 );
103+ $ resumeFile = tempnam (sys_get_temp_dir (), 'resume_file ' );
104+ $ this ->assertNotFalse ($ resumeFile );
105+ list ($ ret , $ error ) = $ upManager ->putFile (
106+ $ token ,
107+ $ key ,
108+ $ tempFile ,
109+ ["x:var_1 " => "val_1 " , "x:var_2 " => "val_2 " , "x-qn-meta-m1 " => "val_1 " , "x-qn-meta-m2 " => "val_2 " ],
110+ 'application/octet-stream ' ,
111+ false ,
112+ $ resumeFile
113+ );
114+ $ this ->assertNull ($ error );
115+ $ this ->assertNotNull ($ ret ['hash ' ]);
116+ $ this ->assertEquals ("val_1 " , $ ret ['var_1 ' ]);
117+ $ this ->assertEquals ("val_2 " , $ ret ['var_2 ' ]);
118+ $ this ->assertEquals (basename ($ tempFile ), $ ret ['fname ' ]);
119+ unlink ($ resumeFile );
120+
121+ $ domain = getenv ('QINIU_TEST_DOMAIN ' );
122+ $ response = Client::get ("http:// $ domain/ $ key " );
123+ $ this ->assertEquals (200 , $ response ->statusCode );
124+ $ this ->assertEquals (md5_file ($ tempFile , true ), md5 ($ response ->body (), true ));
125+ $ this ->assertEquals ("val_1 " , $ response ->headers ()["X-Qn-Meta-M1 " ]);
126+ $ this ->assertEquals ("val_2 " , $ response ->headers ()["X-Qn-Meta-M2 " ]);
127+ unlink ($ tempFile );
128+ }
129+
85130 public function testResumeUploadV2 ()
86131 {
87- $ key = 'resumePutFile4ML ' ;
88132 $ zone = new Zone (array ('up.qiniup.com ' ));
89133 $ cfg = new Config ($ zone );
90134 $ upManager = new UploadManager ($ cfg );
91- $ token = $ this ->auth ->uploadToken ($ this ->bucketName , $ key );
92135 $ testFileSize = array (
93136 config::BLOCK_SIZE / 2 ,
94137 config::BLOCK_SIZE ,
@@ -98,6 +141,8 @@ public function testResumeUploadV2()
98141 );
99142 $ partSize = 5 * 1024 * 1024 ;
100143 foreach ($ testFileSize as $ item ) {
144+ $ key = 'resumePutFile4ML_ ' .rand ()."_ " ;
145+ $ token = $ this ->auth ->uploadToken ($ this ->bucketName , $ key );
101146 $ tempFile = qiniuTempFile ($ item );
102147 $ resumeFile = tempnam (sys_get_temp_dir (), 'resume_file ' );
103148 $ this ->assertNotFalse ($ resumeFile );
@@ -115,7 +160,47 @@ public function testResumeUploadV2()
115160 $ this ->assertNull ($ error );
116161 $ this ->assertNotNull ($ ret ['hash ' ]);
117162 unlink ($ resumeFile );
163+
164+ $ domain = getenv ('QINIU_TEST_DOMAIN ' );
165+ $ response = Client::get ("http:// $ domain/ $ key " );
166+ $ this ->assertEquals (200 , $ response ->statusCode );
167+ $ this ->assertEquals (md5_file ($ tempFile , true ), md5 ($ response ->body (), true ));
118168 unlink ($ tempFile );
119169 }
120170 }
171+
172+ public function testResumeUploadV2WithParams ()
173+ {
174+ $ key = "resumePutFile4ML_ " .rand ();
175+ $ upManager = new UploadManager ();
176+ $ policy = array ('returnBody ' => '{"hash":$(etag),"fname":$(fname),"var_1":$(x:var_1),"var_2":$(x:var_2)} ' );
177+ $ token = $ this ->auth ->uploadToken ($ this ->bucketName , $ key , 3600 , $ policy );
178+ $ tempFile = qiniuTempFile (4 * 1024 * 1024 + 10 );
179+ $ resumeFile = tempnam (sys_get_temp_dir (), 'resume_file ' );
180+ $ this ->assertNotFalse ($ resumeFile );
181+ list ($ ret , $ error ) = $ upManager ->putFile (
182+ $ token ,
183+ $ key ,
184+ $ tempFile ,
185+ ["x:var_1 " => "val_1 " , "x:var_2 " => "val_2 " , "x-qn-meta-m1 " => "val_1 " , "x-qn-meta-m2 " => "val_2 " ],
186+ 'application/octet-stream ' ,
187+ false ,
188+ $ resumeFile ,
189+ 'v2 '
190+ );
191+ $ this ->assertNull ($ error );
192+ $ this ->assertNotNull ($ ret ['hash ' ]);
193+ $ this ->assertEquals ("val_1 " , $ ret ['var_1 ' ]);
194+ $ this ->assertEquals ("val_2 " , $ ret ['var_2 ' ]);
195+ $ this ->assertEquals (basename ($ tempFile ), $ ret ['fname ' ]);
196+ unlink ($ resumeFile );
197+
198+ $ domain = getenv ('QINIU_TEST_DOMAIN ' );
199+ $ response = Client::get ("http:// $ domain/ $ key " );
200+ $ this ->assertEquals (200 , $ response ->statusCode );
201+ $ this ->assertEquals (md5_file ($ tempFile , true ), md5 ($ response ->body (), true ));
202+ $ this ->assertEquals ("val_1 " , $ response ->headers ()["X-Qn-Meta-M1 " ]);
203+ $ this ->assertEquals ("val_2 " , $ response ->headers ()["X-Qn-Meta-M2 " ]);
204+ unlink ($ tempFile );
205+ }
121206}
0 commit comments