2016-02-26 149 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可能有幫助,

相關問題