Skip to content

Commit 4d47da3

Browse files
committed
自定义变量
1 parent 677906f commit 4d47da3

File tree

4 files changed

+59
-3
lines changed

4 files changed

+59
-3
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: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,35 @@ class MyRet {
2424
public String mimeType;
2525
}
2626

27+
@Test
28+
public void testXVar() throws IOException {
29+
final String expectKey = "世/界";
30+
File f = null;
31+
try {
32+
f = TempFile.createFile(1024 * 4 + 2341);
33+
} catch (IOException e) {
34+
e.printStackTrace();
35+
}
36+
assert f != null;
37+
StringMap params = new StringMap().put("x:foo", "foo_val");
38+
final String returnBody = "{\"key\":\"$(key)\",\"hash\":\"$(etag)\",\"fsize\":\"$(fsize)\""
39+
+ ",\"fname\":\"$(fname)\",\"mimeType\":\"$(mimeType)\",\"foo\":\"$(x:foo)\"}";
40+
String token = TestConfig.testAuth.uploadToken(TestConfig.bucket, expectKey, 3600,
41+
new StringMap().put("returnBody", returnBody));
42+
43+
try {
44+
UploadManager uploadManager = new UploadManager();
45+
Response res = uploadManager.put(f, expectKey, token, params, null, true);
46+
StringMap m = res.jsonToMap();
47+
assertEquals("foo_val", m.get("foo"));
48+
} catch (QiniuException e) {
49+
assertEquals("", e.response.bodyString());
50+
fail();
51+
} finally {
52+
TempFile.remove(f);
53+
}
54+
}
55+
2756
private void template(int size) throws IOException {
2857
final String expectKey = "\r\n?&r=" + size + "k";
2958
final File f = TempFile.createFile(size);

0 commit comments

Comments
 (0)