1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| @RequestMapping(value = "/upload/video", method = RequestMethod.POST)
@Consumes(MediaType.MULTIPART_FORM_DATA)
@ResponseStatus(HttpStatus.OK)
public void insertVideo(HttpServletRequest request,
HttpServletResponse response) {
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://remote.restful.ws.com/test");
FileBody fileContent= new FileBody(new File(filename));
StringBody comment = new StringBody("Filename: " + fileName");
MultipartEntity reqEntity = new MultipartEntity();
reqEntity.addPart("file", fileContent);
httppost.setEntity(reqEntity);
HttpResponse responseClient = httpclient.execute(httppost);
HttpEntity resEntity = responseClient.getEntity();
System.out.println("Output from Server .... \n");
}catch (Exception e) {
e.printStackTrace();
System.out.println(e);
request.setAttribute("error", e.getMessage());
}
} |
Partager