Last active
August 30, 2019 13:27
-
-
Save blzjns/3c676c4fe14c7445c6c18ea3aa88b0ce to your computer and use it in GitHub Desktop.
multipart akka http scala request formdata file client
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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