Monday, 15 August 2011

javascript - How to store a file together with a REST object -



javascript - How to store a file together with a REST object -

i'm designing rest api handles post/put requests creating/updating collection objects (lets phone call 1 object shoe). shoes may have image attached. i'm looking best way handle shoe-pictures in api. api used 100% pure javascript webclients.

in past i've done multipart form-data: 1 part containing json object (shoe) , other part file or stream (shoe picture). worked php/mobile app clients not browsers/javascript clients cannot set content-type of body parts in multipart request. i'm stuck question how alter api meet needs of browser client.

i'm thinking of cutting file part away json object , have 2 post requests:

@post /api/shoe << shoe json-object ^^ creates new shoe in shoe collection, returns shoe object generated shoe id @post /api/shoe/{shoe-id}/picture << file/stream ^^ creates new shoepicture object generated id. @delete /api/shoe/{shoe-id}/picture/{shoe-picture-id} ^^ deletes shoe-picture described shoe-picture-id @put /api/shoe/{shoe-id}/picture/{shoe-picture-id} << file/stream + json-object ??? ^^ alter shoe-picture described shoe-picture-id

basically shoepicture object json again, can't sent browser... means set can't done. how solve this?

javascript json api rest multipartform-data

No comments:

Post a Comment