0

Am really stuck with this issue for past several days. What I need to achieve is to send a image to server through Multipart. I tried this code but at server its says The request is not a Multipart request

This is how I tried to send image to server on my app

MultipartEntity entity = new MultipartEntity();
entity.addPart(photosPath.getName(), new FileBody(photosPath));

also this is how my app calls the server using restful service

@GET("/api/add/remark")
void addRemark(@Header("Cookies") HttpCookie cookie, @Query("tenantId") long tenantId, @Query("userId") long userId, @Query("comment") String commentJson, @Query("file") MultipartEntityBuilder multipartEntity, Callback<CreationResponse> callback);

at my server side this is how I receive

@RequestMapping("add/remark")
@Secured({"ROLE_ADMIN","ROLE_SITE_USER","ROLE_FIELDUSER"})
@JsonInclude(Include.NON_NULL)
public @ResponseBody 
CreationResponse addRemarkController1(@RequestParam String comment,@RequestParam Integer userId,@RequestParam long tenantId,@RequestParam("file") MultipartFile file,HttpServletRequest request) {}

I don't have a clue how to resole this. Please help

EDIT 1

MultipartEntity entity = new MultipartEntity();
ContentBody contentBody = new FileBody(photosPath,"imgae/jpeg");
entity.addPart("file", contentBody);

i tried this, it's not working

suja
  • 1,198
  • 2
  • 12
  • 32

1 Answers1

0

I think, you should use @Multipart annotation. This is how I am doing it

  @Multipart
@POST("/events")
CreateChatEventCallback sendChatImageSynchronously(@Header("Authorization") String token,
                                                   @Part("type") String type,
                                                   @Part("attachment") TypedFile image,
                                                   @Part("message_id") String messageId);

This article might help,

Huteri
  • 158
  • 2
  • 12