Skip to content

Instantly share code, notes, and snippets.

@jrudolph
Created February 11, 2015 09:52
Show Gist options
  • Save jrudolph/c01c7a38419d16b6f456 to your computer and use it in GitHub Desktop.
Save jrudolph/c01c7a38419d16b6f456 to your computer and use it in GitHub Desktop.
spray file upload example
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