Announcement Announcement Module
Collapse
No announcement yet.
How to RestTemplate Post MultiPart File Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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">
    	<fieldset><legend>Assets</legend>
    		<p><form:label for="name" path="name">Name</form:label><br />
    		<form:input path="fileData" type="file" /></p>
    		
    		<p><input type="submit" /></p>
    	</fieldset>
    </form:form>
    The controller that is using the rest template (here uploadItem is a DTO that contain a Multipart member called fileData):

    Code:
    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:

    Code:
    @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?.

    Thanks!.
    Mauro
    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

    Comment

    Working...
    X