jeudi 26 février 2015

how to upload files using retrofit?

i have a web service controller calss like this



public class User {
private String user; // JSON string
private CommonsMultipartFile photo1;
private CommonsMultipartFile photo2;
private CommonsMultipartFile photo3;
private CommonsMultipartFile photo4;

public User(String user, CommonsMultipartFile photo1, CommonsMultipartFile photo2, CommonsMultipartFile photo3,CommonsMultipartFile photo4) {
this.user = user; this.photo1 = photo1; this.photo2 = photo2;
this.photo3 = photo3; this.photo4 = photo4;}
public String getUser() { return user; }
}


@RequestMapping(value = "/create",method = RequestMethod.POST, produces = "application/json")
public ResponseEntity<String> create(User item) throws Exception {
//remaining code

}


the above create() method accepts object of type User.


In client app i am calling this webservice like bellow using retrofit



@Multipart
@POST("/create")
void createUser(@Part("user") User user,
@PartMap Map<String,TypedFile> files,
Callback<Customer> callback);


But it is giving me no defaut constructor found at controller class in server side. Please check where i am doing wrong


Aucun commentaire:

Enregistrer un commentaire