use of com.koushikdutta.async.http.body.MultipartFormDataBody in project AndroidAsync by koush.
the class MultipartTests method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
httpServer = new AsyncHttpServer();
httpServer.setErrorCallback(new CompletedCallback() {
@Override
public void onCompleted(Exception ex) {
fail();
}
});
httpServer.listen(AsyncServer.getDefault(), 5000);
httpServer.post("/", new HttpServerRequestCallback() {
int gotten = 0;
@Override
public void onRequest(final AsyncHttpServerRequest request, final AsyncHttpServerResponse response) {
final MultipartFormDataBody body = (MultipartFormDataBody) request.getBody();
body.setMultipartCallback(new MultipartCallback() {
@Override
public void onPart(Part part) {
if (part.isFile()) {
body.setDataCallback(new DataCallback() {
@Override
public void onDataAvailable(DataEmitter emitter, ByteBufferList bb) {
gotten += bb.remaining();
bb.recycle();
}
});
}
}
});
request.setEndCallback(new CompletedCallback() {
@Override
public void onCompleted(Exception ex) {
response.send(body.getField("baz") + gotten + body.getField("foo"));
}
});
}
});
}
use of com.koushikdutta.async.http.body.MultipartFormDataBody in project ion by koush.
the class IonRequestBuilder method setMultipartContentType.
@Override
public IonRequestBuilder setMultipartContentType(String contentType) {
if (multipartBody == null) {
multipartBody = new MultipartFormDataBody();
setBody(multipartBody);
}
multipartBody.setContentType(contentType);
return this;
}
use of com.koushikdutta.async.http.body.MultipartFormDataBody in project ion by koush.
the class IonRequestBuilder method addMultipartParts.
@Override
public Builders.Any.M addMultipartParts(Part... parameters) {
if (multipartBody == null) {
multipartBody = new MultipartFormDataBody();
setBody(multipartBody);
}
for (Part part : parameters) {
multipartBody.addPart(part);
}
return this;
}
use of com.koushikdutta.async.http.body.MultipartFormDataBody in project ion by koush.
the class IonRequestBuilder method setMultipartFile.
@Override
public IonRequestBuilder setMultipartFile(String name, String contentType, File file) {
if (multipartBody == null) {
multipartBody = new MultipartFormDataBody();
setBody(multipartBody);
}
FilePart part = new FilePart(name, file);
if (contentType == null)
contentType = AsyncHttpServer.tryGetContentType(file.getAbsolutePath());
if (contentType != null)
part.setContentType(contentType);
multipartBody.addPart(part);
return this;
}
use of com.koushikdutta.async.http.body.MultipartFormDataBody in project ion by koush.
the class IonRequestBuilder method addMultipartParts.
@Override
public IonRequestBuilder addMultipartParts(Iterable<Part> parameters) {
if (multipartBody == null) {
multipartBody = new MultipartFormDataBody();
setBody(multipartBody);
}
for (Part part : parameters) {
multipartBody.addPart(part);
}
return this;
}
Aggregations