I'm working with java using java-spark to create the Rest Api and I'm having trouble figuring out how to receive a file so then I can process it. Haven't found anything as like in Spring that handles MultipartFile
. Also this proyect is ran on a Tomcat server.
Asked
Active
Viewed 872 times
0

elcharrua
- 1,582
- 6
- 30
- 50
1 Answers
2
As per the official documentation, the following code you get you started:
post("/yourUploadPath", (request, response) -> {
request.attribute("org.eclipse.jetty.multipartConfig", new MultipartConfigElement("/temp"));
try (InputStream is = request.raw().getPart("uploaded_file").getInputStream()) {
// Use the input stream to create a file
}
return "File uploaded";
});

Mithfindel
- 4,553
- 1
- 23
- 32
-
I used this config on the documentation and I cant seem to get it working I keep getting a null pointer since .getPart() is null. I'm not receiving the file from a form – elcharrua Jul 03 '18 at 16:09
-
Oh, sorry I did not see you were running on Tomcat. Would this other Q/A be helpful to you? https://stackoverflow.com/questions/40932829/spark-java-unable-to-process-parts-as-no-multi-part-configuration-has-been-prov – Mithfindel Jul 04 '18 at 07:02