Вопрос

I have a servlet which is supposed to process uploaded file. Apache common file upload library is used for that.

The problem is that file comes corrupted. Looks like symbols "~" are replaced on "?" in the file.

Here my html form is:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title></title>
</head>
<body>

<FORM action="http://localhost:8081/wihome-connector-bpm/bpmFileUpload"
      enctype="multipart/form-data"
      method="post">

        What files are you sending?
        <INPUT type="file" name="uploadedFiles"><BR>

        <INPUT type="submit" value="Send">

        <INPUT type="reset">

</FORM>


</body>
</html>

And that is the servlet:

public class FileUploadServlet extends HttpServlet {

    private static final Log LOG = LogFactory.getLog(FileUploadServlet.class);

    /**
     * {@inheritDoc}
     */
    @Override
    protected void doPost(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {


        try {
            boolean isMultipart = ServletFileUpload.isMultipartContent(request);
            if (isMultipart) {
                FileItemFactory factory = new DiskFileItemFactory();
                ServletFileUpload upload = new ServletFileUpload(factory);

                List items = upload.parseRequest(request);

                Iterator iter = items.iterator();
                while (iter.hasNext()) {
                    FileItem item = (FileItem) iter.next();
                    if (!item.isFormField()) {
                        LOG.info("Uploading file: " + item.getName());
                        byte[] fileContents = IOUtils.toByteArray(item.getInputStream());
                        //...
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


}

I am trying to upload image enter image description here

But instead I get that:

enter image description here

Can you please help me? What can be the problem?

Это было полезно?

Решение

Ok, there was a problem with filters. Project had a filter that currupted request before it rich servlet.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top