Saturday, 15 September 2012

android - Uploading a large file in multipart using OkHttp -



android - Uploading a large file in multipart using OkHttp -

what options uploading single big file (more specifically, s3) in multipart in android using okhttp?

from okhttp recipes page, code uploads image imgur:

private static final string imgur_client_id = "..."; private static final mediatype media_type_png = mediatype.parse("image/png"); private final okhttpclient client = new okhttpclient(); public void run() throws exception { // utilize imgur image upload api documented @ https://api.imgur.com/endpoints/image requestbody requestbody = new multipartbuilder() .type(multipartbuilder.form) .addpart( headers.of("content-disposition", "form-data; name=\"title\""), requestbody.create(null, "square logo")) .addpart( headers.of("content-disposition", "form-data; name=\"image\""), requestbody.create(media_type_png, new file("website/static/logo-square.png"))) .build(); request request = new request.builder() .header("authorization", "client-id " + imgur_client_id) .url("https://api.imgur.com/3/image") .post(requestbody) .build(); response response = client.newcall(request).execute(); if (!response.issuccessful()) throw new ioexception("unexpected code " + response); system.out.println(response.body().string()); }

you'll need adapt s3, classes need should same.

android file-upload upload okhttp

No comments:

Post a Comment