2016-02-26 145 views
0

过去几天我们确实遇到了这个问题。我需要实现的是通过Multipart将图像发送到服务器。我想这个代码,但在服务器的说的请求不是多部分请求500使用多部分时发生内部服务器错误

这是我尝试发送图像到服务器上我的应用程序

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

也这是我的应用程序是如何调用服务器使用RESTful服务

@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); 

在我的服务器端,这是我如何接收

@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) {} 

我没有线索如何解决这个问题。请帮助

编辑1

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

我想这一点,它不工作

回答

0

我想,你应该使用@Multipart注解。这是我正在做它

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

This article可能有帮助,