Skip to content

自定义变量 #227

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/com/qiniu/storage/ResumeUploader.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public void accept(String key, Object value) {
b.append("/");
b.append(key);
b.append("/");
b.append(value);
b.append(UrlSafeBase64.encodeToString("" + value));
}
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/com/qiniu/HttpTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ public void testPost1() {
}

@Test
public void testPost2() {
public void testPost2() throws Exception {
Response r = null;
try {
r = httpManager.post("http://up.qiniu.com", "hello", null);
Assert.fail();
} catch (QiniuException e) {
Assert.assertNotNull(e.response.reqId);
Assert.assertEquals(false, e.response.isOK());
}
}

Expand Down
27 changes: 27 additions & 0 deletions src/test/java/com/qiniu/storage/FormUploadTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,33 @@ public void complete(String key, Response r) {
}
}

@Test
public void testXVar() {
final String expectKey = "世/界";
File f = null;
try {
f = TempFile.createFile(1);
} catch (IOException e) {
e.printStackTrace();
}
assert f != null;
StringMap params = new StringMap().put("x:foo", "foo_val");
final String returnBody = "{\"key\":\"$(key)\",\"hash\":\"$(etag)\",\"fsize\":\"$(fsize)\""
+ ",\"fname\":\"$(fname)\",\"mimeType\":\"$(mimeType)\",\"foo\":\"$(x:foo)\"}";
String token = TestConfig.testAuth.uploadToken(TestConfig.bucket, expectKey, 3600,
new StringMap().put("returnBody", returnBody));

try {
Response res = uploadManager.put(f, expectKey, token, params, null, true);
StringMap m = res.jsonToMap();
assertEquals("foo_val", m.get("foo"));
} catch (QiniuException e) {
fail();
} finally {
TempFile.remove(f);
}
}

@Test
public void testFname() {
final String expectKey = "世/界";
Expand Down
41 changes: 35 additions & 6 deletions src/test/java/com/qiniu/storage/ResumeUploadTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,33 @@

public class ResumeUploadTest {

class MyRet {
public String hash;
public String key;
public String fsize;
public String fname;
public String mimeType;
@Test
public void testXVar() throws IOException {
final String expectKey = "世/界";
File f = null;
try {
f = TempFile.createFile(1024 * 4 + 2341);
} catch (IOException e) {
e.printStackTrace();
}
assert f != null;
StringMap params = new StringMap().put("x:foo", "foo_val");
final String returnBody = "{\"key\":\"$(key)\",\"hash\":\"$(etag)\",\"fsize\":\"$(fsize)\""
+ ",\"fname\":\"$(fname)\",\"mimeType\":\"$(mimeType)\",\"foo\":\"$(x:foo)\"}";
String token = TestConfig.testAuth.uploadToken(TestConfig.bucket, expectKey, 3600,
new StringMap().put("returnBody", returnBody));

try {
UploadManager uploadManager = new UploadManager();
Response res = uploadManager.put(f, expectKey, token, params, null, true);
StringMap m = res.jsonToMap();
assertEquals("foo_val", m.get("foo"));
} catch (QiniuException e) {
assertEquals("", e.response.bodyString());
fail();
} finally {
TempFile.remove(f);
}
}

private void template(int size) throws IOException {
Expand Down Expand Up @@ -70,4 +91,12 @@ public void test8M1k() throws Throwable {
}
template(1024 * 8 + 1);
}

class MyRet {
public String hash;
public String key;
public String fsize;
public String fname;
public String mimeType;
}
}