How to make MultipartBbody.Part request from cache image using retrofit

Clash Royale CLAN TAG#URR8PPPHow to make MultipartBbody.Part request from cache image using retrofit
My image is cached at located:
file:///data/user/0/com.example.muhammadusman.project/cache/cropped1340954678061130725.jpg
how can i make the Multipart.body request for this interface:
@Multipart
@POST("/image/{name}")
Call<Recognition> recognizeImage(
@Path("name")String name,
@Part MultipartBody.Part image);
Input to the Function
key="40"
imageName="cropped1340954678061130725.jpg"
path="file:///data/user/0/com.example.muhammadusman.project/cache/cropped1340954678061130725.jpg"
This is My Code: i am using this code to make the MultipartBody.Part object. But i am not able to make the object. Always program crash.
public static MultipartBody.Part creatPartFromPath(String key,String imageName,String path){
File file=new File(path);
String mediaType= getMimeType(path);
RequestBody intermediateFile=RequestBody.create(MediaType.parse(mediaType),file);
return MultipartBody.Part.createFormData(key,imageName,intermediateFile);
}
public static String getMimeType(String url) {
return url.substring(url.lastIndexOf(".") + 1);
}
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.