I think your interface should be like this.
@Multipart
@POST("/Api/ApiSales/UploadImages")
void uploadImage(@Header("Authorization") String user,
@Part("File") TypedFile file, Callback<Response> callback);
you must first get your real image path from onActivityResult
final String imagePath = getRealPathFromURI(imageUri);
and getRealPathFromURI will be like that.
private String getRealPathFromURI(Uri contentUri) {
String[] projection = {MediaStore.Images.Media.DATA};
CursorLoader loader = new CursorLoader(this, contentUri, projection, null, null, null);
Cursor cursor = loader.loadInBackground();
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
String result = cursor.getString(column_index);
cursor.close();
return result;
}
and intialize your TypedFile
File photoFile = new File(imagePath);
String mimeType = getMimeType(imagePath);
TypedFile photoTypedFile;
if (mimeType != null) {
photoTypedFile = new TypedFile(mimeType, photoFile);
} else {
photoTypedFile = new TypedFile("image/jpg", photoFile);
}
and your intialize of your Restadapter will be the same except for adding headers, and your call will be like that.
RetrofitService service = restAdapter.create(RetrofitService.class);
service.uploadImage("yourAuthorization", photoTypedFil, new Callback<retrofit.client.Response>() {
@Override
public void success(retrofit.client.Response response, retrofit.client.Response response2) {
Log.i(TAG, response.toString());
}
@Override
public void failure(RetrofitError error) {
Log.e(TAG, error.toString());
}
});