use of com.koushikdutta.async.http.AsyncHttpClient.StringCallback in project AndroidAsync by koush.
the class MultipartTests method testUpload.
public void testUpload() throws Exception {
setUp();
try {
File dummy = getContext().getFileStreamPath("dummy.txt");
final String FIELD_VAL = "bar";
dummy.getParentFile().mkdirs();
FileOutputStream fout = new FileOutputStream(dummy);
byte[] zeroes = new byte[100000];
for (int i = 0; i < 10; i++) {
fout.write(zeroes);
}
fout.close();
// StreamUtility.writeFile(dummy, DUMMY_VAL);
AsyncHttpPost post = new AsyncHttpPost("http://localhost:5000");
MultipartFormDataBody body = new MultipartFormDataBody();
body.addStringPart("foo", FIELD_VAL);
body.addFilePart("my-file", dummy);
body.addStringPart("baz", FIELD_VAL);
post.setBody(body);
Future<String> ret = AsyncHttpClient.getDefaultInstance().executeString(post, new StringCallback() {
@Override
public void onCompleted(Exception e, AsyncHttpResponse source, String result) {
}
});
String data = ret.get(10000, TimeUnit.MILLISECONDS);
assertEquals(data, FIELD_VAL + (zeroes.length * 10) + FIELD_VAL);
} finally {
tearDown();
}
}
Aggregations