Announcement Announcement Module
Collapse
No announcement yet.
Reading XML file into MultipartFile omits xml tags is not working properly Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Reading XML file into MultipartFile omits xml tags is not working properly

    I have a Spring MVC appliation with file upload UI.

    When the user uploads the file it maps to a `org.springframework.web.multipart.MultipartFile` object. I then use the `getInputStream()` in order to get an `InputStream` to the file and then convert it to String using `org.apache.commons.io.IOUtils.toString()`.

    In my beans decleration I am using:

    Code:
        <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        		<property name="defaultEncoding" value="UTF-8"/>
        	</bean>

    The problem is that when the user uploads an xml file the String representation only contains the values of the xml, so for example if the user uploads this file:

    Code:
        <note><to>John</to><body>Hello</body></note>
    The String representation of it using the above will be `JohnHello`.

    Now, If I create a very simple standalone java application and read the same file using `FileInputStream` then convert it to String using `org.apache.commons.io.IOUtils.toString()` I will see the correct output which contains the entire xml, so this makes me think the problem is with Spring. Should probably mention that I tried many other methods to read the file (including playing with encoding) and also got the same result - Works with a simple standalone Java application but not when doing this from a Spring MVC application context.
Working...
X