Skip to content

Commit 440607d

Browse files
authored
Merge pull request #227 from sxci/7.0
自定义变量
2 parents 677906f + a348f69 commit 440607d

File tree

4 files changed

+65
-9
lines changed

4 files changed

+65
-9
lines changed

src/main/java/com/qiniu/storage/ResumeUploader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public void accept(String key, Object value) {
165165
b.append("/");
166166
b.append(key);
167167
b.append("/");
168-
b.append(value);
168+
b.append(UrlSafeBase64.encodeToString("" + value));
169169
}
170170
});
171171
}

src/test/java/com/qiniu/HttpTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ public void testPost1() {
2222
}
2323

2424
@Test
25-
public void testPost2() {
25+
public void testPost2() throws Exception {
2626
Response r = null;
2727
try {
2828
r = httpManager.post("http://up.qiniu.com", "hello", null);
2929
Assert.fail();
3030
} catch (QiniuException e) {
31-
Assert.assertNotNull(e.response.reqId);
31+
Assert.assertEquals(false, e.response.isOK());
3232
}
3333
}
3434

src/test/java/com/qiniu/storage/FormUploadTest.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,33 @@ public void complete(String key, Response r) {
170170
}
171171
}
172172

173+
@Test
174+
public void testXVar() {
175+
final String expectKey = "世/界";
176+
File f = null;
177+
try {
178+
f = TempFile.createFile(1);
179+
} catch (IOException e) {
180+
e.printStackTrace();
181+
}
182+
assert f != null;
183+
StringMap params = new StringMap().put("x:foo", "foo_val");
184+
final String returnBody = "{\"key\":\"$(key)\",\"hash\":\"$(etag)\",\"fsize\":\"$(fsize)\""
185+
+ ",\"fname\":\"$(fname)\",\"mimeType\":\"$(mimeType)\",\"foo\":\"$(x:foo)\"}";
186+
String token = TestConfig.testAuth.uploadToken(TestConfig.bucket, expectKey, 3600,
187+
new StringMap().put("returnBody", returnBody));
188+
189+
try {
190+
Response res = uploadManager.put(f, expectKey, token, params, null, true);
191+
StringMap m = res.jsonToMap();
192+
assertEquals("foo_val", m.get("foo"));
193+
} catch (QiniuException e) {
194+
fail();
195+
} finally {
196+
TempFile.remove(f);
197+
}
198+
}
199+
173200
@Test
174201
public void testFname() {
175202
final String expectKey = "世/界";

src/test/java/com/qiniu/storage/ResumeUploadTest.java

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,33 @@
1616

1717
public class ResumeUploadTest {
1818

19-
class MyRet {
20-
public String hash;
21-
public String key;
22-
public String fsize;
23-
public String fname;
24-
public String mimeType;
19+
@Test
20+
public void testXVar() throws IOException {
21+
final String expectKey = "世/界";
22+
File f = null;
23+
try {
24+
f = TempFile.createFile(1024 * 4 + 2341);
25+
} catch (IOException e) {
26+
e.printStackTrace();
27+
}
28+
assert f != null;
29+
StringMap params = new StringMap().put("x:foo", "foo_val");
30+
final String returnBody = "{\"key\":\"$(key)\",\"hash\":\"$(etag)\",\"fsize\":\"$(fsize)\""
31+
+ ",\"fname\":\"$(fname)\",\"mimeType\":\"$(mimeType)\",\"foo\":\"$(x:foo)\"}";
32+
String token = TestConfig.testAuth.uploadToken(TestConfig.bucket, expectKey, 3600,
33+
new StringMap().put("returnBody", returnBody));
34+
35+
try {
36+
UploadManager uploadManager = new UploadManager();
37+
Response res = uploadManager.put(f, expectKey, token, params, null, true);
38+
StringMap m = res.jsonToMap();
39+
assertEquals("foo_val", m.get("foo"));
40+
} catch (QiniuException e) {
41+
assertEquals("", e.response.bodyString());
42+
fail();
43+
} finally {
44+
TempFile.remove(f);
45+
}
2546
}
2647

2748
private void template(int size) throws IOException {
@@ -70,4 +91,12 @@ public void test8M1k() throws Throwable {
7091
}
7192
template(1024 * 8 + 1);
7293
}
94+
95+
class MyRet {
96+
public String hash;
97+
public String key;
98+
public String fsize;
99+
public String fname;
100+
public String mimeType;
101+
}
73102
}

0 commit comments

Comments
 (0)