Reputation: 49057
I have a path like POST /animals/1/images
. I have read in the documentation that you can declare MultipartFile
as a parameter and it will contain the file. But is this right? I mean, when you only have one file to upload (or an array of files) do I need to use the content type multipart/form-data
? If not, how should the method signature be?
Upvotes: 3
Views: 4828
Reputation: 11
You can use this code fragment:
@POST
@Path("/uploadfile")
public void upload(File file) {
//TODO code goes here
}
Upvotes: 1
Reputation: 27535
As far as I know if you are uploading any file with POST via HTTP protocol, you have to use multipart/form-data
. The form-data
is just a name since usually (always?) when you are sending something via HTTP you use form.
Using MultipartFile
parameter is a valid solution for this case - of course unless you prefer to write a whole Command object with MultipartFile as its only property, which would be preferred way, according to conventions.
Upvotes: 0