dextaa
dextaa

Reputation: 31

Sending Image: post, put or json?

I need to send an image from a client application (Java) to my web server (play framework). However, it needs to be secure - not necessarily as in encrypted but transfer needs to be assigned to a specific user and only the client application can use it - no web browsers or 3rd party apps

Which am I better of using - Using post or sending as binary json?

Upvotes: 0

Views: 104

Answers (1)

taylonr
taylonr

Reputation: 10790

You've created a false sense of options here. First, you can POST or PUT and have the data still be sent across as json (or XML for that matter.) So if you were to chose POST or PUT you can still use json.

As for it being secure, that's something you'd need to check on your web server. Pass in the credentials for the user as well as perhaps a unique token that only the application has access to. Then check on the server side for these parameters. If they're not there, return a 403 (forbidden.)

With that in mind, I'd argue that whether you use PUT or POST is dependent on who is controlling the picture. What I mean is, if you want to let the client application determine that this picture's ID is 123, then you should do a PUT with the ID specified.

If you want to let the server determine that the picture's id is actually 456, you should do a POST without specifying an id, but returning it to the client application.

Upvotes: 1

Related Questions