Reputation: 1417
Given the Play Framework sample code from their documentation, here https://www.playframework.com/documentation/2.3.x/ScalaFileUpload:
def upload = Action(parse.temporaryFile) { request =>
request.body.moveTo(new File("/tmp/picture/uploaded"))
Ok("File uploaded")
}
How would I go about implementing this on the client side? What we have been doing until now is multipart file uploads, and handling the data model as a JSON request, then following it with a multipart binary stream. It's a bit complicated and I'd love to simplify.
So when I stumbled on the above, it looked fantastic. But, I've no idea what the "other side" of that connection might look like.
(FYI, our client is iOS and Swift, but obviously what I really need to understand is the client-side protocol).
Upvotes: 0
Views: 197
Reputation: 4966
The client side protocol is HTTP POST as the documentation shows us with the HTML form.
For an example a request might look like this:
POST http://localhost:9000/api/upload HTTP/1.1
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip, deflate
Content-Type: multipart/form-data; boundary=---------------------------41184676334
Content-Length: 29278
-----------------------------41184676334
Content-Disposition: form-data; name="file2"; filename="picture.jpg"
Content-Type: image/jpeg
(Binary data)
-----------------------------41184676334--
So you would have to construct a POST request in Swift. Maybe this stackoverflow question or this gist can help.
Upvotes: 1