Last active
August 29, 2015 14:27
-
-
Save ariefbayu/4c5c50ee3f9441a9fc1a to your computer and use it in GitHub Desktop.
OkHttp recipe for uploading files with additional form inputs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File file1 = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/Master/CAM_" + s.getType() + "_" + s.getJobCode() + ".jpg"); | |
File file2 = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/Master/SIGN_" + s.getType() + "_" + s.getJobCode() + ".jpg"); | |
Log.d("LOG", "File1: "+ (file1.exists() ? "E" : "N") + " -> " + file1.getAbsolutePath()); | |
Log.d("LOG", "File2: "+ (file2.exists() ? "E" : "N") + " -> " + file2.getAbsolutePath()); | |
RequestBody requestBody = new MultipartBuilder() | |
.type(MultipartBuilder.FORM) | |
.addFormDataPart("gambar1", file1.getName(), | |
RequestBody.create(MEDIA_TYPE_IMAGE, file1)) | |
.addFormDataPart("gambar2", file2.getName(), | |
RequestBody.create(MEDIA_TYPE_IMAGE, file2)) | |
.addFormDataPart("job", s.getJobCode()) | |
.addFormDataPart("auth", dp.getLoginAuth()) | |
.addFormDataPart("lat", String.valueOf(s.getLatitude())) | |
.addFormDataPart("lon", String.valueOf(s.getLongitude())) | |
.addFormDataPart("acc", String.valueOf(s.getAccuracy())) | |
.addFormDataPart("tipe", s.getType()) | |
.addFormDataPart("tanggal", s.getTanggal()) | |
.addFormDataPart("pemberi", s.getPemberi()) | |
.addFormDataPart("penerima", s.getPenerima()) | |
.addFormDataPart("penandatangan", s.getPenandatangan()) | |
.addFormDataPart("catatan", s.getCatatan()) | |
.addFormDataPart("rate", String.valueOf(s.getRate())) | |
.build(); | |
Request request = new Request.Builder().url(URL_UPLOAD_SIGNATURE).post(requestBody).build(); | |
Response response = client.newCall(request).execute(); | |
Log.d("LOG", s.getType() + " Resonse: " + response.body().string()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment