I am working on a project that needs to save user's information including the profile image to the server using retrofit. the backend was built with java spring boot and the profile image was declared as a string in the backend. I want to pick an image from my gallery by using a crop image and save the image to the server so that I can retrieve it anytime from the server and upload it when the user logins. I am still a beginner in android app development so I don't know how to go about that. I have picked and cropped the image successfully but the image path cannot be formatted to a string that can be stored and retrieved anytime. I really need help here. Thanks
Here is the code.
imagePicker.setOnClickListener(view -> {
CropImage.activity()
.setAspectRatio(1,1)
.start(PatientRegistrationActivity.this);
});
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode==CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE && resultCode==RESULT_OK && data !=null){
CropImage.ActivityResult result = CropImage.getActivityResult(data);
Uri profileImageUri = result.getUri();
profilePicture.setImageURI(profileImageUri);//profilePicture here is imageview that displays the picked image from the gallery
String imagePath= profileImageUri.getPath();
Log.d("Main","Your image path is "+imagePath);
}else {
Toast.makeText(PatientRegistrationActivity.this,"Error Occurred, Please try Again",Toast.LENGTH_SHORT).show();
}
}