Created
February 11, 2015 09:52
-
-
Save jrudolph/c01c7a38419d16b6f456 to your computer and use it in GitHub Desktop.
spray file upload example
This file contains hidden or 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 akka.actor.ActorSystem | |
import spray.client.pipelining._ | |
import spray.http.{MediaTypes, BodyPart, MultipartFormData} | |
object UploadFileExample extends App { | |
implicit val system = ActorSystem("simple-spray-client") | |
import system.dispatcher // execution context for futures below | |
val pipeline = sendReceive | |
val payload = MultipartFormData(Seq(BodyPart(new File("/tmp/test.pdf"), "datafile", MediaTypes.`application/pdf`))) | |
val request = | |
Post("http://localhost:8080/file-upload", payload) | |
pipeline(request).onComplete { res => | |
println(res) | |
system.shutdown() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment