Save Camera Store File MultiPart UdayAndroid

//1->Here it is the onActivityResultCode this get from EsayImage File multiPartFile2; Uri uri; @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == 1) { b = BitmapFactory.decodeByteArray(data.getByteArrayExtra("byteArray"), 0, data.getByteArrayExtra("byteArray").length); /*signImage.setImageBitmap(b); byteArray = data.getByteArrayExtra("byteArray"); Signaturepic = getStringImage(b);*/ uri = getImageUri(getApplicationContext(), b); signImage.setImageURI(uri); filePath = getRealPathFromUri(uri,DeliveryOrderForm.this); multiPartFile2 = new File(filePath); Signaturepic = multiPartFile2.toString(); Log.d("ok", "onActivityResult: "+multiPartFile2+"\n"+multiPartFile2.getName()); } //getImageUri from Bitmap public Uri getImageUri(Context inContext, Bitmap inImage) { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); inImage.compress(Bitmap.CompressFormat.JPEG, 100, bytes); String path = MediaStore.Images.Media.insertImage(inContext.getContentResolver(), inImage, "Title", null); return Uri.parse(path); } //getRealPathFromUri from Uri//it returns the real path of image that stores in our device private String getRealPathFromUri(Uri contentUri,Activity activity){ int index= 0; Cursor cursor; String finalres= ""; if(activity != null && contentUri != null){ cursor = activity.getContentResolver().query(contentUri,null,null,null,null); if(cursor == null){ return contentUri.getPath(); }else { cursor.moveToFirst(); index = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA); finalres = cursor.getString(index); return finalres; } } return finalres; } //Send the image file to the Server Retrofit retrofit = new Retrofit.Builder() .baseUrl(Utility.DeliveryformUrl) .addConverterFactory(GsonConverterFactory.create()) .build(); quantity_key=quantityET.getText().toString(); minQuantity_key=minQuantityET.getText().toString(); grade_key=gradeET.getText().toString(); Date toPrint = new Date(); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); format.setTimeZone(TimeZone.getTimeZone("Asia/XXXXX")); System.out.println(format.format(toPrint)); Dateee = format.format(toPrint); Log.i("Date", Dateee); if (Dateee.contains(" ")){ Dateee = Dateee.replace(" ", "_"); Log.i("Date", Dateee); } RequestBody requestFileClientDoForm = RequestBody.create(MediaType.parse("multipart/form-data"), multiPartFile); RequestBody requestFileClientSign = RequestBody.create(MediaType.parse("multipart/form-data"), multiPartFile2); final MultipartBody.Part bodyClientDoForm = MultipartBody.Part.createFormData("clientDOform", multiPartFile.getName(), requestFileClientDoForm); final MultipartBody.Part bodyClientSign = MultipartBody.Part.createFormData("clientsig", multiPartFile2.getName(), requestFileClientSign); RetofitDeliveryApi service = retrofit.create(RetofitDeliveryApi.class); Call<DeliveryBean> call = service.delivery(sharedPref.GetUserId(),Sonum, finOdometer, bodyClientSign,Remarks, UpdateStatus,Weight,TareWeight,GrossWeight,bodyClientDoForm, Dateee, Ddonum,quantity_key,minQuantity__key,grade_key,reason_Key); Call<DeliveryBean> call = service.delivery(sharedPref.GetUserId(),fieldname, fieldname, bodyClientSign,fieldname, fieldname,fieldname,fieldname,fieldname,bodyClientDoForm, fieldname, fieldname,fieldname,fieldname,fieldname,fieldname); // And here is the API @POST("end_url") @Multipart Call<DeliveryBean> delivery(@Part("key") String value, @Part("key") String value, @Part("key") String value, @Part MultipartBody.Part clientsig, @Part("v") String value, @Part("key") String value, @Part("key") String value, @Part("key") String value, @Part("key") String value, @Part MultipartBody.Part clientDOform, @Part("key") String value, @Part("key") String value, @Part("key") String value, @Part("key") String value, @Part("key") String value, @Part("key") String value); }
This explains how to save the captured or selected image in onActivityResult and how to get that picture into bitmap or Uri.
Talks about , get the Uri From Bitmap
Talks about, get the File Path From Uri
Talks about, how to store the images that selected from EasyImage in a File
Talks about, how to send that file to server using MultiPart and Retrofit2
Talks about, how to send multiple files to server too.

1 Response

Thank You ..

Write a comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.