Skip to content

Instantly share code, notes, and snippets.

@blzjns
Last active August 30, 2019 13:27
Show Gist options
  • Save blzjns/3c676c4fe14c7445c6c18ea3aa88b0ce to your computer and use it in GitHub Desktop.
Save blzjns/3c676c4fe14c7445c6c18ea3aa88b0ce to your computer and use it in GitHub Desktop.
multipart akka http scala request formdata file client
import java.nio.file.{Path, Paths}
import akka.stream.scaladsl.Source
val foo: Path = Paths.get("/images/foo.jpg")
val bar: Path = Paths.get("/images/bar.png")
val data = Multipart.FormData {
Source {
List (
Multipart.FormData.BodyPart.fromPath("foo", ContentTypes.`application/octet-stream`, foo),
Multipart.FormData.BodyPart.fromPath("bar", ContentTypes.`application/octet-stream`, bar)
)
}
}
//or
data = Multipart.FormData(
Multipart.FormData.BodyPart.fromPath("foo", ContentTypes.`application/octet-stream`, foo)
)
entity:HttpEntity = data.toEntity()
Post(uri = s"/images/").withEntity(entity)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment