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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:07:18+00:00 2026-05-27T06:07:18+00:00

So I am doing an ajax(jquery) post that uploads quite a big amount of

  • 0

So I am doing an ajax(jquery) post that uploads quite a big amount of json data. When posting a large data, the data is generally broken into chunks. So we have to listen for post data requests and construct a full buffer of the upload data. Something like this:

    req.on('data', function(chunk) {
        console.log("upload on data "+ chunk.length);
        chunks.push(chunk);
        total+= chunk.length;
    });
    req.on('error', function(e) {
            console.log('Got Error ' + e.message);
    });
    req.on('end', function() {
        var buf = new Buffer(total)
            cur = 0;
        for (var i = 0, l = chunks.length; i < l; i++) {
            chunks[i].copy(buf, cur, 0);
            cur += chunks[i].length;
        }

        var level = 1;
        var path = "level"+level+".json";
        writeToFile(buf,path);
        res.send("Update successfull as level "+level);
    });

This seems to be working if I am uploading a file with form:

function display_form(req, res) {
    res.sendHeader(200, {"Content-Type": "text/html"});
    res.write(
        '<form action="/upload" method="post" enctype="multipart/form-data">'+
        '<input type="file" name="upload-file">'+
        '<input type="submit" value="Upload">'+
        '</form>'
    );
    res.close();
}

But I need to upload json data (which is dynamic). I am doing this in this way:

           $.ajax({
                type: "POST",
                url: "/upload",
                data: {"data": JSON.stringify(gamePack)},
                success: cb,
            });

Then there seems to be no callback to req ‘data’ or ‘end’. So how are uploading files different from posting data?

  • 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-27T06:07:19+00:00Added an answer on May 27, 2026 at 6:07 am

    This seems to have solved my problem:

    $.ajax({
            type: "POST",
            dataType: 'json',
            url: "/upload",
            contentType:"application/jsonrequest",
            data: JSON.stringify(gamePack),
            success: cb,
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm doing a jQuery AJAX post like this: var form = $(#formid); form.submit(function() {
I have some jquery code that is doing an ajax lookup and returning comma
I am doing an AJAX call that returns some HTML and jQuery: <div id='selected'>Here
I was doing some self-learning on how to pass data from JQuery Ajax to
I'm trying to send POST data that is 2 million characters big (non-binary string)
I am doing an ajax request through post that contains a forms variables. the
I'm having trouble updating the DOM when doing an AJAX post using JQuery. This
I'm doing user auth via an Ajax post-request in Rails, and I thought that
I want a modal dialog that says Please wait, calculating, to appear while jquery.ajax
I have the following JQUERY code that I'm expecting to return 3 json results

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.