Answer the question
In order to leave comments, you need to log in
How to send a file using POST method via JSON?
Good afternoon, the question is the following:
I am making an application that works through the REST API.
By the POST method, it accepts JSON, in which a text file must also be transmitted.
Accordingly, I have several questions:
1) How to send a file? (a bunch of guides, a little confused)
2) How should a class be described in Java that will receive request data?
3) By the architecture itself: if you send data from the front through a form, will it no longer be a REST API?
Answer the question
In order to leave comments, you need to log in
Good afternoon!
To receive a file in the controller, use the MultiPartFile interface
https://docs.spring.io/spring-framework/docs/curre...
And an array of bytes is sent through the client. For example, if a client means some js-framework or just an html form, then pay attention to:
enctype="multipart/form data"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question