Monitoring AJAX POST progress with Node.js and Multipart: XMLHttpRequest

Is there a way to provide real-time updates on the size of a file being uploaded to a client, similar to how YouTube does it? I've looked into getting the full size of the file with req.files.myFile.size, but is there a method to track the current size of the file on the disk during the upload process? Thank you for any assistance!

Answer №1

If you want to track the progress of a form submission using XHR2's progress event, take a look at the documentation provided on MDN. Here is a sample code snippet:

var xhr = new XMLHttpRequest();
xhr.open('POST', '/upload', true);
xhr.onload = function(e) { ... };

// The HTML element for upload progress
var progressBar = document.querySelector('progress#uploadProgress');
// Listen for upload progress events
xhr.upload.onprogress = function(e) {
  if (e.lengthComputable) {
    progressBar.value = (e.loaded / e.total) * 100;
    progressBar.textContent = progressBar.value;
  }
};

var form = new FormData(document.querySelector('form#uploadForm'));
xhr.send(form);

Although this code snippet tracks the progress of the entire form submission, not individual files.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Absolute positioning causes an element's height to increase

As I delve into the realm of typographical animations and seek to calculate the baseline of a font at various sizes, I've stumbled upon a peculiar discovery: It appears that the height values of elements tend to increase in an erratic manner when thei ...

Expand the image to fill the entirety of the viewing area

Check out my development website. Whenever you click on an image, a photo slider (using photoswipe) pops up. Is there any way to have the image fill the entire viewport? I attempted using height: 100vh, width: auto, but it didn't work. ...

What is the best way to enforce a required selection from one of the toggle buttons in a React form?

Is there a way to require the user to click one of the toggle buttons in a react form? I need to display an error message if the user submits the form without selecting a button. I tried using the "required" attribute in the form but it didn't work. H ...

Is the npm installation failing? Could it be due to a node js issue, fsevents conflict, Xcode error,

Hello there, friends! Can you lend me a helping hand? I've encountered an issue. Whenever I run the npm install command, I face this problem: natalakolivosko@192 webpack-static-template % npm install > <a href="/cdn-cgi/l/email-protection" clas ...

Error: The npm-link library encountered an invalid hook call

Problem Description: I am working on developing a package named eformless. To set up the package, I utilized CRA to create a directory named sandbox where I linked the package. However, I keep encountering an error when attempting to launch the sand ...

Using Apache Proxy to host Node.js and Wordpress under one "Domain" with distinct paths

Let's delve into the scenario. I currently have a Wordpress website operating on my primary domain, http://www.example.com. The server has .htaccess enabled and I am utilizing Wordpress permalinks for generating neat URLs. In addition to this, I hav ...

Testing Your Angular 7 Code: Unit Testing Made Easy

I am currently working on developing unit tests for this angular script: export class DataService { private csrfToken: string = ''; private isContentShown: BehaviorSubject<boolean> = new BehaviorSubject(true); constructor(private h ...

I have a Three.js Group containing five elements, but I am having trouble accessing the meshes within. Is there a way to properly access the meshes within a Three.js group?

https://i.sstatic.net/cfznC.png I am encountering an issue while trying to access elements within this array. Despite there being a length of 5, the code returns "undefined" and has a length of 0. The image above shows the output of this code. console.log ...

Problem: Repeated attempts to open the popup are unsuccessful

Developed a leaflet map featuring markers that open popups when clicked. Also integrated a search bar for marker searchability. However, encountering an issue where each popup can only be opened once and on selecting a marker name, the zoom functionality w ...

JavaScript Popup Box Failing to Trigger

Snippet of Code: <form method="post" id="cp_ind_form"> // several input fields here... <input type="submit" name="update_submit" value="Update" /> <input type="submit" name="delete_submit" value="Delete" onclick="deleteConfi ...

Can the mDNS string received through webRTC be decoded to retrieve a user's IP address?

After doing some thorough research, I came across this insightful response from a different Stack Overflow question. The problem at hand involves retrieving an mDNS string, which looks like this: abcd1234-1e1e-1e1e-1e1e-abcd1a2bc3de.local I have a genuin ...

Deactivate input areas while choosing an option from a dropdown menu in HTML

I've been working on creating a form and have everything set up so far. However, I'm looking to disable certain fields when selecting an option from a dropdown list. For instance, if the "within company" option is selected for my transaction typ ...

Switch Tabs with Dropdown Selection

I came across a website with a similar feature, but I am interested in using a dropdown menu instead of a button or link. Check out this webpage for reference The problem seems to be related to this line of code: onchange="$('#'+$this).tri ...

The margin-top property in CSS is not functioning as intended for a specific pixel value when applied to

I'm having trouble with positioning an icon using margin-top: -35px; under #menu. When I click on the icon, the side navigation bar doesn't work properly. However, if I adjust it to -15px, the side navigation bar displays correctly. Can someone h ...

Step-by-step guide on incorporating an external JavaScript library into an Ionic 3 TypeScript project

As part of a project, I am tasked with creating a custom thermostat app. While I initially wanted to use Ionic for this task, I encountered some difficulty in integrating the provided API into my project. The API.js file contains all the necessary function ...

Error when trying to install with pnpm: ERR_PNPM_LINKING_FAILED ("unable to complete operation, rename[...]")

After setting up a brand new Windows (11) system and installing Node, pnpm, and other necessary tools, I encountered an issue when trying to run pnpm install. The error message that appeared was: "ERR_PNPM_LINKING_FAILED Error: EPERM: operation not p ...

Developing pledges in AngularJS

I am currently working on implementing a promise in Angular using the $q service to retrieve an object from a web service. The unique aspect of this implementation is that if the object is already cached, it should be returned without making a call to the ...

Storing text containing < and > symbols in a PHP Database

I am facing an issue trying to save a string from my web application into the database I'm connected to. The JavaScript successfully passes the string to PHP using AJAX, but when the insertion is performed, everything after the "<" or ">" symbo ...

Experiencing difficulties in retrieving req.body data while using postman to send application/x-www-form-urlencoded data, despite having already implemented body

As the title suggests, I am facing an issue while sending multipart form data from Postman. The data includes several text fields along with an image. However, when I use console.log(req.body), the output shows: { '------WebKitFormBoundaryCpNHg1P01 ...

Difficulty with Horizontal Mousewheel Scrolling

Struggling to implement a horizontal scrolling feature (via mousewheel) for both containers in the code below. I want this feature to be easily applied to any future container creations as well. <body> <style> #container { display: flex ...