Service params:
{\"id\":\"1\",\"name\":\"vishal\",\"image/file\":\"\"}
As simple way, I have done like this:
I have tested by changing
Call resultCall = service.uploadImage(body);
to
Call where result is
Result.java class (Response) of my API:
public class Result {
@SerializedName("result")
@Expose
private String result;
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
@SerializedName("value")
@Expose
private String value;
/**
* @return The result
*/
public String getResult() {
return result;
}
/**
* @param result The result
*/
public void setResult(String result) {
this.result = result;
}
}
and created object like:
Result result = new Result();
result.setResult("success");
result.setValue("my value");
You can change your class as per your need then pass object when you send request. So your ApiService class will be like:
ApiService.java
/**
* @author Pratik Butani on 23/4/16.
*/
public interface ApiService {
/*
Retrofit get annotation with our URL
And our method that will return us the List of Contacts
*/
@Multipart
@POST("upload.php")
Call uploadImage(@Part MultipartBody.Part file, @Part("result") Result result);
}
and My PHP code is:
"success", "value" => $var);
} else{
$result = array("result" => "error");
}
echo json_encode($result);
?>
Hope it will helps you. Thank you.