P粉9940928732023-08-21 12:54:55
You can send files and data in one request using the multipart/form-data content type:
From http://www.faqs.org/rfcs/rfc2388.html:
You can include file information or field information in each section between each boundary. I have successfully implemented a RESTful service that requires users to submit data and forms, multipart/form-data works perfectly. The service is built using Java/Spring and the client uses C#, so unfortunately I don't have a Grails example to give you on how to set up the service. In this case you don't need to use JSON as each "form-data" section gives you a place to specify the parameter names and their values.
The benefit of using multipart/form-data is that you are using the headers defined by HTTP, so you follow the REST philosophy of using existing HTTP tools to create services.
P粉1455438722023-08-21 11:24:16
I asked a similar question here:
How to upload files with metadata using REST web service?
You basically have three options:
multipart/form-data
and return the ID to the client. The client then sends metadata using that ID, and the server reassociates the file and metadata.