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 8837285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:41:05+00:00 2026-06-14T09:41:05+00:00

I am using the html5 filereader API to get photos locally without the user

  • 0

I am using the html5 filereader API to get photos locally without the user having to upload them.

In browsers that support it I am allowing multiple selections so I am looping through the selected files and performing a function on each one (TC.editor.renderSlide()) as shown below:

 handlePhotoUploads: function(event) {
    var self = this;
    TC.dialog.destroy();
    var files = event.target.files;
    var count = files.length + TC.editor.cache.slides.length;
    for (var i = 0, f; f = files[i]; i++) {
        if (!f.type.match('image.*')) {
            continue;
        }
        var reader = new FileReader();
        var index = TC.editor.getNewSlidesIndex();
        TC.editor.addNewSlide('photo', index);
        reader.onload = (function(theFile) {
            var slideindex = index;
            return function(e) {
                TC.editor.renderSlide(slideindex, e.target.result, 'internal', count);
            };
        })(f);
        reader.readAsDataURL(f);
    }
},

The problem is that the TC.editor.renderSlide() function can take a significant amount of time to perform (performs canvas and DOM manipulations) so when dealing with 8 or so large image files the browser gets locked for a substantial amount of time. Even the ‘processing gif’s stop animating during this period.

Is there any way to ensure that each reader.onload event fires only after the previous one has completed? This way the user would be given regular progress updates by seeing the result of each call to TC.editor.renderSlide() individually rather than the current situation which locks the browser while everything is being processed?

I have tried adding a simple setTimeout to renderSlide() to no avail?

Any help or ideas would be greatly appreciated.

  • 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-14T09:41:08+00:00Added an answer on June 14, 2026 at 9:41 am

    The onload events do fire sequentially, the handler is not executed while an other one is currently processed (“JS is single-threaded”). This of course does not count when you start some asynchronous processing (timeouts, animations, file loads) in a handler.

    In that case, you will need to manually handle the sequential processing. It’s easy using a queue of waiting processes which are executed when one is finished:

    var waiting = [];
    // …create many parallel loaders, and on each:
        ….onevent = execute;
    
    function execute(e) {
        if (waiting.active)
            waiting.push(e);
        else {
            waiting.active = true
            // do something that takes its time, supplying a
              … function callback(ready) {
                waiting.active = false;
                if (waiting.length)
                    execute(waiting.shift()); // go on with next
              }
        }
    }
    

    However, it seems to me that not renderSlide is causing the problems, but that you instantiate so many FileReaders at the same time. Make them start loading files one after the other, by turning your for-loop into an asynchronously called “recursive” function:

    var files = […]
    (function handle(i) {
         if (i >= files.length) return;
         // create loader
         ….onevent = function(e) {
              // do processing, and then call
              handle(i+1);
              // or call that from another callback if you want to do async
              // processing, like "renderSlide"
         };
    })(0);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using html5 javascript, how do you get the file path when user select the
Using the HTML5 File API I can get the Binary String representation of a
Using HTML5 File API I am able to read text and XML files without
Can someone give me an example of using the FileReader API go get contents
I'm trying to do some experiment with HTML5, WebSocket and File API. I'm using
I am investigating using HTML5 for a new suite of mobile applications that our
Using HTML5 I have an input field that should validate against a dollar amount
Using HTML5 upload multiple is it possible to have a wildcard upload. Means if
I'm having problems trying to upload files using the latest XHR 2 along with
I'm trying to implement an HTML5 Amazon S3 uploader (by using the REST API),

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.