I am trying to upload an image to the Webserver using retrofit.
The API has been developed using Dot Net. The API is working fine on postman but shows error in android.
URL: https://m13tp89pn9.execute-api.us-west-2.amazonaws.com/Prod/api/user/UploadImag/userid=67
Authorization = Bearer token
This is my interface
@Headers("Content-Type: multipart/form-data")
@Multipart
@POST("user/UploadImage")
Call<GeneralPOJO> uploadProfileImage(@Query ("userid") int uid,
@Part MultipartBody.Part image, @Header("Authorization")String header);
This is my Code
final String path = getPathFromURI(selectedImageUri);
if (path != null) {
File file = new File(path);
RequestBody mFile = RequestBody.create(MediaType.parse("multipart/form-data"), file);
MultipartBody.Part fileToUpload = MultipartBody.Part.createFormData("file", file.getAbsolutePath(), mFile);
RequestBody filename = RequestBody.create(MediaType.parse("text/plain"), file.getName());
new RestCaller(ProfileActivity.this, MainApplication.getRestClient().getApiServices().
uploadProfileImage(AppSession.getInt(Constants.LOGIN_UDID), fileToUpload, AppSession.get(Constants.LOGIN_TOKEN)), Constants.REQUEST_CODE_PROFILE_PICTURE);
Please help me in uploading the image to the server successfully. Please correct my code and tell me what change is required. Thanks