You can build your own directive to extract the content-type:
val contentType =
headerValuePF {
case `Content-Type`(ct) => ct
}
and then use it in your route:
put {
entity(as[Array[Byte]]) { data =>
contentType { ct => // ct is instance of spray.http.ContentType
// ...
}
}
}
Edit: If you are on the nightly builds, MediaTypes already contain file extensions so you could use the ones from there. On 1.1-M7 you have to provide your own mapping as you suggested.