Hi,

I've created the following service:

        Encrypted file
              +
              | Uploaded to
              |
        +-----v-----+
        |           |
        | Amazon S3 |
        |           |
        +---^---+---+ Receive resp and return
            |   |     
HttpResponse(entity=resp.entity.dataBytes.via(decryptionFlow))
            |   |       +----------------------------+
            |   +------->                            +---------> Decrypted 
file with unknown mime type
            |           | Decrypt & download service |
            +-----------+                            <---------+
Request encrypted file  +----------------------------+  Request file


It works like a charm, with a JVM constrained to 128Mo of memory I can 
download file of many Go without any problem (because I forward the source 
of bytes).
But to be perfect, I would like to set the Content-Type header of the 
response containing the decrypted file, because now it's just binary data.

To achieve that goal I want to use Apache Tika (it's a library used to 
detect mime type). Apache Tika need some bytes to do its work.

So here is my problem, how can I peek some data from the decrypted bytes, 
detect the mime type, and when done, return the HttpResponse with the 
correct header and with the entity set with the Source of decrypted bytes?

val decryptedBytesSource = resp.entity.dataBytes.via(decryptionFlow)
val contentType = ???? detectContentType(decryptedBytesSource) ????
HttpResponse(entity = HttpEntity(contentType, decryptedBytesSource))

I know the code above doesn't work as I can't consume the source twice, 
it's just to show what I want to do.

Thank you in advance :)
Victor

-- 
>>>>>>>>>>      Read the docs: http://akka.io/docs/
>>>>>>>>>>      Check the FAQ: 
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>>      Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to