I want to create a form-data http request to Facebook API using Akka HTTP. In curl, the request example looks like:
curl
-X POST
"https://graph-video.facebook.com/v2.3/1533641336884006/videos"
-F "access_token=XXXXXXX"
-F "upload_phase=transfer"
-F "start_offset=0"
-F "upload_session_id=1564747013773438"
-F "[email protected]"
So I created a following model for a request payload representation:
case class FBSingleChunkUpload(accessToken: String,
sessionId: String,
from: Long,
to: Long,
file: File) //file is always ~1Mb
Then I’m going to use:
Http().cachedHostConnectionPoolHttps[String]("graph-video.facebook.com")
But I don’t know how to convert FBSingleChunkUpload
to the correct HttpRequest
🙁
Can you give me a hint, how to represent a such type of requests using Akka HTTP?
2
Answers
There is an
FormData
Entity
type for thatAdditionally for the file you could check if it works with
Multipart.FormData
In curl, the
-F
option stipulates a POST using the “multipart/form-data” content type. To create such a request in Akka HTTP, useMultipart.FormData
(defaultEntity
below is borrowed from Akka HTTP’sMultipartSpec
):