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

  • SEARCH
  • Home
  • 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 8394623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:06:27+00:00 2026-06-09T20:06:27+00:00

I will start with the question: How to use Scala API’s Iteratee to upload

  • 0

I will start with the question: How to use Scala API’s Iteratee to upload a file to the cloud storage (Azure Blob Storage in my case, but I don’t think it’s most important now)

Background:

I need to chunk the input into blocks of about 1 MB for storing large media files (300 MB+) as an Azure’s BlockBlobs. Unfortunately, my Scala knowledge is still poor (my project is Java based and the only use for Scala in it will be an Upload controller).

I tried with this code: Why makes calling error or done in a BodyParser's Iteratee the request hang in Play Framework 2.0? (as a Input Iteratee) – it works quite well but eachElement that I could use has size of 8192 bytes, so it’s too small for sending some hundred megabyte files to the cloud.

I must say that’s quite a new approach to me, and most probably I misunderstood something (don’t want to tell that I misunderstood everything ;> )

I will appreciate any hint or link, which will help me with that topic. If is there any sample of similar usage it would be the best option for me to get the idea.

  • 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-09T20:06:28+00:00Added an answer on June 9, 2026 at 8:06 pm

    Basically what you need first is rechunk input as bigger chunks, 1024 * 1024 bytes.

    First let’s have an Iteratee that will consume up to 1m of bytes (ok to have the last chunk smaller)

    val consumeAMB = 
      Traversable.takeUpTo[Array[Byte]](1024*1024) &>> Iteratee.consume()
    

    Using that, we can construct an Enumeratee (adapter) that will regroup chunks, using an API called grouped:

    val rechunkAdapter:Enumeratee[Array[Byte],Array[Byte]] =
      Enumeratee.grouped(consumeAMB)
    

    Here grouped uses an Iteratee to determine how much to put in each chunk. It uses the our consumeAMB for that. Which means the result is an Enumeratee that rechunks input into Array[Byte] of 1MB.

    Now we need to write the BodyParser, which will use the Iteratee.foldM method to send each chunk of bytes:

    val writeToStore: Iteratee[Array[Byte],_] =
      Iteratee.foldM[Array[Byte],_](connectionHandle){ (c,bytes) => 
        // write bytes and return next handle, probable in a Future
      }
    

    foldM passes a state along and uses it in its passed function (S,Input[Array[Byte]]) => Future[S] to return a new Future of state. foldM will not call the function again until the Future is completed and there is an available chunk of input.

    And the body parser will be rechunking input and pushing it into the store:

    BodyParser( rh => (rechunkAdapter &>> writeToStore).map(Right(_)))
    

    Returning a Right indicates that you are returning a body by the end of the body parsing (which happens to be the handler here).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use following style attribute so when i will start typing in text box
I'm just finishing a relatively big project in scala and will start another related
We have legacy applications which soon they will start to use common jsp pages.
I will start with the question and then proceed to explain the need: Given
I will start new project which is based on ASP.NET MVC 3 using C#
I will start new PDA project on the windows mobile and compact framework 2.0
I will start by saying that I don't think what I want can be
As we all know Java program will start executing from the public static void
I wrote an init script to execute last that will start some pythjon script.
I have an asp.net page that calls a dll that will start a long

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.