Announcement Announcement Module
No announcement yet.
How to RestTemplate Post MultiPart File Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to RestTemplate Post MultiPart File

    Hi everyone,

    Im trying to use the rest template to post a file to a Spring Controller, but i am getting an converter error all the time.

    i have this:

    HTML Code:
    <form:form method="post" modelAttribute="uploadDTO"	enctype="multipart/form-data">
    		<p><form:label for="name" path="name">Name</form:label><br />
    		<form:input path="fileData" type="file" /></p>
    		<p><input type="submit" /></p>
    The controller that is using the rest template (here uploadItem is a DTO that contain a Multipart member called fileData):

    URI postUpload = new URI("http://localhost:8080/yoostar/admin/1.0/UploadTestFile");
    MultiValueMap<String, Object> variablesMap = new LinkedMultiValueMap<String, Object>();
    variablesMap.add("file", uploadItem.getFileData());
    Map<String, Object> wsResponse = super.getRestTemplate().postForObject(postUpload, variablesMap, Map.class);
    On my Webservice side (another application) i have a controller that looks like:

    @RequestMapping(value = "/UploadTestFile", method = { RequestMethod.GET, RequestMethod.POST })
    public ModelAndView getFile(@RequestParam("file", required=false) MultipartFile file) {
        if (file == null) {
            System.out.println("file null .. exit...");    
            return null;

    I dont know if i have to use any specific converter ... something like a MultipartFileHttpMessageConverter? There is any converter to convert MultiPartFiles?.
    I have to implement my own converter?.

    Last edited by mauro_monti; Oct 28th, 2010, 03:22 PM.

  • #2
    How to RestTemplate Post MultiPart File

    Any suggestion? Just i want to know if it can be done.
    Last edited by mauro_monti; Nov 1st, 2010, 10:15 AM. Reason: rest template multipart