perwendel / spark

A simple expressive web framework for java. Spark has a kotlin DSL https://github.com/perwendel/spark-kotlin
Apache License 2.0
9.64k stars 1.56k forks source link

File upload on another web server (eg jboss) #916

Closed ndr-brt closed 7 years ago

ndr-brt commented 7 years ago

Hi, we're trying to upload files with spark (2.6.0) deployed on a jboss eap (6.4.5) we already look at #26 but no way to make it work!

call to req.raw().getParts() always returns an empty collection

any idea? :)

post("/ca", "multipart/form-data", (req, res) -> {
    // this line is useless on jboss!
    req.raw().setAttribute("org.eclipse.jetty.multipartConfig", new MultipartConfigElement(getProperty("java.io.tmpdir")));

    try (InputStream stream = req.raw().getPart("file").getInputStream()) {
        upload(stream);
        res.status(201);
        return res;
    }
});
tipsy commented 7 years ago

"org.eclipse.jetty.multipartConfig" won't work if you're not using jetty. You can use https://commons.apache.org/proper/commons-fileupload/streaming.html to get the files instead?

ndr-brt commented 7 years ago

Ok, thanks. We were used with resteasy and it handled everything by itself ;)

mlitcher commented 6 years ago

I don't have a lot of experience with JBoss, but I had a similar issue with WebSphere (unable to use the Servlet 3.0 getPart/getParts methods). For WebSphere to process multipart/form data, you must specify the multipart-config by annotating the servlet with @MutlipartConfig, or specifying the multipart-config options in web.xml, neither of which you can do in Spark as-is.

However, I was able to apply a change along the lines of #671 (ability to use a servlet instead of filter). There is no change in functionality, and allowed me to specify the needed multipart-config in our web.xml.