Skip to content

Export content as static file in Spray

April 30, 2013

If you want to export some text as a file using Spray scala library, here is an example:

respondWithHeader(`Content-Type`(new ContentType(MediaTypes.`text/plain`, None))) {
   respondWithHeader(`Content-Disposition`("attachment", Map(("filename", fileName)))) {
      complete {

and use these imports:

import spray.http.HttpHeaders._
import spray.http.HttpCharsets._
import spray.http.MediaTypes._
import spray.http.ContentType
import spray.http.MediaTypes


From → Scala, Slick

  1. I think this post is misnamed, though very useful It should be using Spray, not Slick.

  2. Thanks Eric, I just fixed it.

  3. Micaela Marbury permalink

    Useful ideas . I was fascinated by the info , Does anyone know if my assistant could possibly locate a template a form form to work with ?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: