Search in sources :

Example 6 with MultipartFormDataBody

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"));
                }
            });
        }
    });
}
Also used : CompletedCallback(com.koushikdutta.async.callback.CompletedCallback) HttpServerRequestCallback(com.koushikdutta.async.http.server.HttpServerRequestCallback) ByteBufferList(com.koushikdutta.async.ByteBufferList) AsyncHttpServerRequest(com.koushikdutta.async.http.server.AsyncHttpServerRequest) AsyncHttpServerResponse(com.koushikdutta.async.http.server.AsyncHttpServerResponse) MultipartCallback(com.koushikdutta.async.http.body.MultipartFormDataBody.MultipartCallback) DataCallback(com.koushikdutta.async.callback.DataCallback) Part(com.koushikdutta.async.http.body.Part) DataEmitter(com.koushikdutta.async.DataEmitter) AsyncHttpServer(com.koushikdutta.async.http.server.AsyncHttpServer) MultipartFormDataBody(com.koushikdutta.async.http.body.MultipartFormDataBody)

Example 7 with MultipartFormDataBody

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;
}
Also used : MultipartFormDataBody(com.koushikdutta.async.http.body.MultipartFormDataBody)

Example 8 with MultipartFormDataBody

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;
}
Also used : FilePart(com.koushikdutta.async.http.body.FilePart) Part(com.koushikdutta.async.http.body.Part) MultipartFormDataBody(com.koushikdutta.async.http.body.MultipartFormDataBody)

Example 9 with MultipartFormDataBody

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;
}
Also used : MultipartFormDataBody(com.koushikdutta.async.http.body.MultipartFormDataBody) FilePart(com.koushikdutta.async.http.body.FilePart)

Example 10 with MultipartFormDataBody

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;
}
Also used : FilePart(com.koushikdutta.async.http.body.FilePart) Part(com.koushikdutta.async.http.body.Part) MultipartFormDataBody(com.koushikdutta.async.http.body.MultipartFormDataBody)

Aggregations

MultipartFormDataBody (com.koushikdutta.async.http.body.MultipartFormDataBody)10 Part (com.koushikdutta.async.http.body.Part)5 AsyncHttpServer (com.koushikdutta.async.http.server.AsyncHttpServer)4 AsyncHttpServerRequest (com.koushikdutta.async.http.server.AsyncHttpServerRequest)4 AsyncHttpServerResponse (com.koushikdutta.async.http.server.AsyncHttpServerResponse)4 HttpServerRequestCallback (com.koushikdutta.async.http.server.HttpServerRequestCallback)4 CompletedCallback (com.koushikdutta.async.callback.CompletedCallback)3 FilePart (com.koushikdutta.async.http.body.FilePart)3 File (java.io.File)2 ByteBufferList (com.koushikdutta.async.ByteBufferList)1 DataEmitter (com.koushikdutta.async.DataEmitter)1 DataCallback (com.koushikdutta.async.callback.DataCallback)1 StringCallback (com.koushikdutta.async.http.AsyncHttpClient.StringCallback)1 AsyncHttpPost (com.koushikdutta.async.http.AsyncHttpPost)1 AsyncHttpResponse (com.koushikdutta.async.http.AsyncHttpResponse)1 NameValuePair (com.koushikdutta.async.http.NameValuePair)1 JSONObjectBody (com.koushikdutta.async.http.body.JSONObjectBody)1 MultipartCallback (com.koushikdutta.async.http.body.MultipartFormDataBody.MultipartCallback)1 StringBody (com.koushikdutta.async.http.body.StringBody)1 UrlEncodedFormBody (com.koushikdutta.async.http.body.UrlEncodedFormBody)1