N
N
Nightmare0582021-05-23 16:45:25
Spring
Nightmare058, 2021-05-23 16:45:25

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

1 answer(s)
O
Orkhan Hasanli, 2021-05-23
@azerphoenix

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"

https://developer.mozilla.org/en/docs/Learn/Forms/...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question