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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:51:51+00:00 2026-05-24T09:51:51+00:00

I’ve been playing with Valum’s AJAX upload script: http://valums.com/ajax-upload/ It ticks all the boxes

  • 0

I’ve been playing with Valum’s AJAX upload script: http://valums.com/ajax-upload/

It ticks all the boxes for me, not using the horrid swfupload flash object for one. I have the JS point at my .ashx script (which for love-nor-money I cannot debug). This is what I have in the .ashx:

public class avatar : IHttpHandler, System.Web.SessionState.IRequiresSessionState {

public void ProcessRequest (HttpContext context) {
    //Debugger.Break();

string result = "{\"success\":true}";
    string path = HttpContext.Current.Server.MapPath("/client/vault/" + Helpers.CurrentClientHash(context.Session["SessionHash"].ToString()) + "/users/" + context.Session["SessionHash"].ToString() + "/");
    string saveLocation = string.Empty;
    string fileName = string.Empty;

    try
    {
        int length = 4096;
        int bytesRead = 0;
        Byte[] buffer = new Byte[length];

        //This works with Chrome/FF/Safari
        // get the name from qqfile url parameter here
        Debugger.Break();
        fileName = context.Request["params"];
        Debug.Write(fileName);

        saveLocation = context.Server.MapPath(path) + fileName;

        try
        {
            using (FileStream fileStream = new FileStream(saveLocation, FileMode.Create))
            {
                do
                {
                    bytesRead = context.Request.InputStream.Read(buffer, 0, length);
                    fileStream.Write(buffer, 0, bytesRead);
                }
                while (bytesRead > 0);
            }
        }
        catch (UnauthorizedAccessException ex)
        {
            // log error hinting to set the write permission of ASPNET or the identity accessing the code
            result = result.Replace("true","false, \"error\":" + ex.Message + " " + ex.InnerException + " " + ex.StackTrace.ToString());
        }
}
catch
{
    try
        {
            //This works with IE
            fileName = Path.GetFileName(context.Request.Files[0].FileName);
            saveLocation = context.Server.MapPath(path) + fileName;
            context.Request.Files[0].SaveAs(saveLocation);
        }
    catch (Exception ex)
        {
            result = result.Replace("true", "false, \"error\":" + ex.Message + " " + ex.InnerException);
        }
}
context.Response.Write(result);
}

public bool IsReusable {
    get {
        return false;
    }
}

}

This code was kindly offered up by another user of the Valum’s script, because it ships with PHP server-side stuff. When I run the uploader, I get this in the console:

[uploader] responseText = {“success”:false, “error”:Index was out of
range. Must be non-negative and less than the size of the collection.
Parameter name: index }

…and the upload of course fails. I’m sure it has something to do with the FileStream, but without meaningful debugging I can’t find the problem. I think it might be because the file isn’t being picked-up by the .ashx, but it’s in the params:

bust uploader...

So, I have two questions if I may:

  1. Can anyone see, right-off-the-bat where or why I’m getting the index exception?
  2. If not, how can I debug this thing? I can’t just run the debugger from VS2010, because non of the JS seems to load. I can’t obviously go directly to the ashx either… Any ideas?

Help 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-05-24T09:51:53+00:00Added an answer on May 24, 2026 at 9:51 am

    Unfortunately, I never solved this. I uninstalled the Valams script and went for Plupload.

    Plupload was easier, it supports HTML5, Flash, Gears and BrowserPlus. It was a no brainer in the end. Here is the working code for those looking for a C# AJAX Uploader widget:

    <script type="text/javascript" src="/js/jquery.min.js"></script>
    
        <script type="text/javascript" src="http://bp.yahooapis.com/2.4.21/browserplus-min.js"></script>
        <script type="text/javascript" src="/js/plupload.js"></script>
    
        <script type="text/javascript" src="/js/plupload.html5.js"></script>
        <script type="text/javascript" src="/js/plupload.gears.js"></script>
        <script type="text/javascript" src="/js/plupload.browserplus.js"></script>
        <script type="text/javascript" src="/js/plupload.silverlight.js"></script>
        <script type="text/javascript">
            // Custom example logic
            function $(id) {
                return document.getElementById(id);
            }
    
    
            var uploader = new plupload.Uploader({
                runtimes: 'gears,html5,silverlight,browserplus',
                browse_button: 'pickfiles',
                max_file_size: '2mb',
                multi_selection: false,
                url: '/components/uploadify/avatar.ashx',
                silverlight_xap_url: '/js/plupload.silverlight.xap',
                filters: [
                    { title: "Image files", extensions: "jpg,gif,png" }
                ]
            });
    
            uploader.bind('Init', function (up, params) {
                $('filelist').innerHTML = "<div>Current runtime: " + params.runtime + "</div>";
            });
    
            uploader.bind('FilesAdded', function (up, files) {
                for (var i in files) {
                    $('filelist').innerHTML += '<div id="' + files[i].id + '">' + files[i].name + ' (' + plupload.formatSize(files[i].size) + ') <b></b></div>';
                }
            });
    
            uploader.bind('UploadFile', function (up, file) {
                $('uploader').innerHTML += '<input type="hidden" name="file-' + file.id + '" value="' + file.name + '" />';
            });
    
            uploader.bind('UploadProgress', function (up, file) {
                $(file.id).getElementsByTagName('b')[0].innerHTML = '<span>' + file.percent + "%</span>";
            });
    
            uploader.bind('FileUploaded', function (up, file, obj) {
                alert("I've done uploading stuff...");
    
            });
    
            $('uploadfiles').onclick = function () {
                uploader.start();
                return false;
            };
    
            uploader.init();
    </script>
    

    And the C# .ashx…

    public class avatar : IHttpHandler, System.Web.SessionState.IRequiresSessionState {
    
        public void ProcessRequest (HttpContext context) {
            string path = "/a/path/to/someplace/";
            if (context.Request.Files.Count > 0)
            {
                int chunk = context.Request["chunk"] != null ? int.Parse(context.Request["chunk"]) : 0;
                string fileName = context.Request["name"] != null ? context.Request["name"] : string.Empty;
    
                HttpPostedFile fileUpload = context.Request.Files[0];
    
                var uploadPath = path;
                using (var fs = new FileStream(Path.Combine(uploadPath, fileName), chunk == 0 ? FileMode.Create : FileMode.Append))
                {
                    var buffer = new byte[fileUpload.InputStream.Length];
                    fileUpload.InputStream.Read(buffer, 0, buffer.Length);
    
                    fs.Write(buffer, 0, buffer.Length);
                }
            }
    
        }
    
        public bool IsReusable {
            get {
                return false;
            }
        }
    
    }
    

    It maybe worthwhile noting, that if you want to access a session whilst in the .ashx, you’ll just need to add SessionState.IRequiresSessionState as shown.

    I hope peeps find this helpful 🙂

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

Sidebar

Related Questions

I am using Paperclip to handle profile photo uploads in my app. They upload
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
We are using XSLT to translate a RIXML file to XML. Our RIXML contains

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.