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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:23:03+00:00 2026-05-26T17:23:03+00:00

I have the following script, which works successfully till the last file slice is

  • 0

I have the following script, which works successfully till the last file slice is to be uploaded, where it fails (the error code block is fired). I am unable to understand why.

function startUpload(fileElementId, blockLength, uploadProgressElement) {
var start = 0;
var end = blockLength;
var incrimentalIdentifier = 1;
var totalNumberOfBlocks = 0;
var file = document.getElementById(fileElementId).files[0];
var progressBar = document.getElementById(uploadProgressElement);
if (file.size <= 0) {
    alert('Please select a file!');
    return;
}

do {
    if (end > file.size - 1) {
        end = file.size - 1;
    }

    if ((file.size % blockLength) == 0) {
        totalNumberOfBlocks = parseInt(file.size / blockLength);
    }
    else {
        totalNumberOfBlocks = parseInt(file.size / blockLength) + 1;
    }

    var reader = new FileReader();
    reader.onloadend = function (evt) {
        if (evt.target.readyState == FileReader.DONE) {
            $.ajax({
                type: "POST",
                url: "/Home/UploadBlock",
                data: { "identifier": incrimentalIdentifier, "fileName": file.name, "payload": evt.target.result },
                dataType: "json",
                success: function () {
                    progressBar.value = Math.round((incrimentalIdentifier / totalNumberOfBlocks) * 100);
                },
                error: function () {
                    alert('failure');
                }
            });
        }
    };

    var payload = file.webkitSlice(start, end);
    reader.readAsText(payload, 'UTF-8');
    start = end + 1;
    incrimentalIdentifier += 1;
    end = start + blockLength - 1;
} while (end < file.size - 1);

}

I am not doing anything in my action yet, but will add body soon. Currently the action is:

 public ActionResult UploadBlock(int identifier, string fileName, string payload)
    {

        return null;
    }
  • 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-05-26T17:23:03+00:00Added an answer on May 26, 2026 at 5:23 pm

    Finally I have been able to resolve my issue with the help of many SO users who are simply awesome. esp. @Raynos and @David and so many others.

    The above given code had a bug in iterator which never went till last block. I have refined the solution several times now and it is now available for download at this link.

    Hope you find it fitting your scenarios in some way or the other.

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

Sidebar

Related Questions

I have the following lua script : module(modoo,package.seeall) foo=1 bar={12,34} Which works fine using
I have the following Ruby script that creates a Debian package, which works fine:
I have the following script which works perfectly until I regenerate the links .resultLink
I have the following script which works kind of... $(document).ready(function(){ // add or remove
I have the following code which works perfect in IE for a textarea element.
I have the following script which works with a 1 dimensional array. Is it
I have the following script which works very will: http://jsfiddle.net/oshirowanen/uUAqe/ I just need to
I have the following script which works almost perfectly: http://jsfiddle.net/oshirowanen/uUAqe/ I just need it
Hi I have the following script which works fine running on IIS but when
I have the following script which works as long as the are static html

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.