I am new to spring boot and android development. I'm trying to set up and android app (using retrofit and okhttp3) which will upload images to my server.
Server code:
@RestController
public class ImageController {
@RequestMapping(value = "/uploadImage", method =RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public String greeting(@RequestPart(value="desc") RequestBody desc, @RequestPart(value="img") MultipartBody.Part image) {
System.out.println("Works");
return "Works";
}
}
Android code:
MultipartBody.Part fileToUpload = MultipartBody.Part.createFormData("file", imageFile.getName(), requestBody);
RequestBody name = RequestBody.create(MediaType.parse("text/plain"), imageFile.getName());
@Multipart
@POST("/uploadImage")
Observable<retrofit2.Response<String>> uploadPhoto(@Part("desc") RequestBody desc,@Part MultipartBody.Part image);
Error:
{"timestamp":1519756785858,"status":415,"error":"Unsupported Media Type","exception":"org.springframework.web.HttpMediaTypeNotSupportedException","message":"Content type 'text/plain;charset=utf-8' not supported","path":"/uploadImage"}
Can someone tell me what I'm doing wrong????