I need to develop the severless application using java11 without spring. In this application i need to open an endpoint where the consumer is multipart/form-data. I know in spring we have a MultipartFile class using which we can grab the object and use it but i want to know how to do it without spring. After that i need to upload that file in amazon S3.
I am using Amazon Api gateway to expose the endpoint and amazon s3 for storage.

- 63
- 9
-
Does [this](https://stackoverflow.com/questions/41956365/spring-rest-multipart-file-upload-with-java-configuration-without-spring-boot) help? – Z-100 Feb 07 '23 at 09:27
-
No, its using spring but we don't want to use any framework. – Shivam Feb 07 '23 at 09:30
-
Could you improve your question? The "using java11 **with** spring" is sorta misleading, given that a sentence later you're saying "without spring". – Z-100 Feb 07 '23 at 09:35
-
Thank you, just edited. I want the ans wothout spring. – Shivam Feb 07 '23 at 09:39
-
Thanks for the edit. So you want to create a Java-App, which **accepts** `multipart/form-data`? Are you using jakarta/javax by any chance? – Z-100 Feb 07 '23 at 09:41
-
javax yes we are using – Shivam Feb 07 '23 at 09:45
-
not the upload part just how to grab the multipart file from the restapi – Shivam Feb 07 '23 at 09:46
-
Are you developing an application with servlets? – dan1st Feb 07 '23 at 09:48
-
application is serverless. using aws lambda – Shivam Feb 07 '23 at 09:52
-
Can you show the relevant code? – dan1st Feb 07 '23 at 09:53
-
You might want to take a look at [this](https://github.com/CorkHounds/multipart-fileupload-java-lambda/blob/master/src/main/java/fileupload/FileUploadFunctionHandler.java) and [that](https://stackoverflow.com/questions/43875504/parse-multipart-form-data-body-on-aws-lambda-in-java). – dan1st Feb 07 '23 at 09:57
-
@Shivam so you ARE using libraries, you said you don't want to... – jwenting Feb 07 '23 at 10:00
-
Are you allowed to use jax-rs and jersey (glassfish) libraries? – John Williams Feb 07 '23 at 10:03
-
Can use library but not from spring. – Shivam Feb 07 '23 at 10:04
-
You need to include some code in this. "i need to open an endpoint where the consumer is multipart/form-data." What is this? How are you obtaining it? Do you have an actual java class that this is in reference to? Are you trying to handle an http request that has multipart/form-data? – matt Feb 07 '23 at 10:06
-
The JavaMail library, part of standard Java EE, includes a [MimeMultipart](https://javaee.github.io/javaee-spec/javadocs/javax/mail/internet/MimeMultipart.html) class. – VGR Feb 07 '23 at 18:34
-
Can you possibly add serverless to the title somewhere? – John Williams Feb 08 '23 at 12:50
2 Answers
Note that on the way to your Serverless Java Lambda the AWS ApiGateway will transform your request into JSON for passing through to Lambda.
To get this to work for multipart form you need to define multipart/form-data as a binary media type for your API and proxy the payload directly to a Lambda function.
This is how you implement the Lambda in Java to consume the resulting payload.
No Spring in sight. Just apache commons and aws stuff.

- 4,252
- 2
- 9
- 18
-
Thank you very much. It worked for me. It take some time to figure out how to do it in my code. – Shivam Feb 14 '23 at 09:40
-
My pleasure. Can you please put “serverless” in the question title somewhere. – John Williams Feb 14 '23 at 09:57
So you don't want to use ANY libraries? In that case you first have to implement your own code to handle http requests, and then code to extract the data you want from them.
I seriously doubt you want to do that (though it's an interesting exercise if you have the time and skill).
But if you insist, the HTTP RFC is where you want to start.

- 5,505
- 2
- 25
- 30