Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8531449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:29:06+00:00 2026-06-11T09:29:06+00:00

I have an application written using Spray , and I have a page which

  • 0

I have an application written using Spray, and I have a page which has an <input type="file" name="foo"> form element that gets POSTed to /fileUpload.

I have a Spray route set up to listen to the path /fileUpload using this code:

path("fileUpload") {
  get { ctx => {
    val request: HttpRequest = ctx.request
    //Process the file, somehow with request?
    ctx.complete("File Uploaded")
  }}
}

I can’t figure out how to get the POST body and get a handle on the file, and I can’t find any examples online.

It must be possible to receive a file and process it with Spray or even through simple Scala or Java, but I don’t know how to do it.

Can anybody help?
Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T09:29:08+00:00Added an answer on June 11, 2026 at 9:29 am

    It’s possible with Spray, although I haven’t checked if streaming works properly. I fiddled a bit and got this working:

      post {
        content(as[MultipartFormData]) {
          def extractOriginalText(formData: MultipartFormData): String = {
            formData.parts.mapValues { (bodyPart) =>
              bodyPart.content.map{
                (content) => new String(content.buffer)
              }
            }.values.flatten.foldLeft("")(_ + _)
          }
          formData =>
            _.complete(
              extractOriginalText(formData)
            );
        }
    

    If you upload a plain text file to a service that has this code in it, it coughs the original text back up. I’ve got it running together with an ajax upload; it should also work with an old fashioned file upload form.

    It seems to me that there must be an easier way to do this, particularly the deep nesting of the content is rather clunky. Let me know if you find a simplification.

    UPDATE (thx akauppi):

    entity(as[MultipartFormData]) { formData => 
      complete( formData.fields.map { _.entity.asString }.flatten.foldLeft("")(_ + _) ) 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application written using Prism 4.0. It has lots of Views which
I have web application written in java using Eclipse. It has just one servlet
I have a C# application of which some parts are written using WPF (which
I have an CMS application which is written using C#, and I should Save
My application is written using : Embarcadero Delphi 2010 I have a form named
I have a web application written using CherryPy, which is run locally on 127.0.0.1:4321
I have an application written in c++ using visual studio 2005. The application has
I have an application written in platform-independent C++ which has been primarily developed on
I have a large application written using .Net remoting for file transfer. This was
I have an application written using C++ Builder 5 that uses the TDocument class.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.