java - REST API Design sending JSON data and a file to the api in same request -


i creating rest api on top of existing application. 1 of features takes in json data along file uploaded user.

i unsure how send file , json data in same request rest api?

i have json part working , test using curl:

curl -xpost http://localhost:8080/myapp/foo -d '{"mydata": {     "name": "somename",     "gender": "male" }}' //i send image (say, profile image) above request well. 

i'm using grails application data in controller so: new foo(params.mydata).

question

  • is possible send json data , file in same request api? if so, how can using curl or rest console (chrome extension)
  • what contenttype of request?
  • i'm open sending data in format if means can send file , other data (strings) within same request. i'm not tied on json

update

i found another question asking same thing. the answer question seems there 3 choices , none of possible send both, json data , file, within same request. discouraging...i keep question open see if has other ideas.

i think "right" way multipart message. way, can post both json , image corresponding correct mime type. wikipedia article on multipart mime types has example of like. looks both apache httpcommons , jersey support sort of thing, , apparently curl too!


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -