How to fix XmlHttpRequest PUT File Upload error when uploading files larger than 1MB

Uploading files to a server (in this case, S3) has been a smooth process for files under ~1MB. However, larger files tend to fail intermittently during the send operation. The issue does not seem to be related to security measures, CORS settings, or signing procedures as small files work fine.

Interestingly, even some larger files do not fail immediately; they trigger progress events indicating correct byte counts until eventually an error occurs and the upload stops. Occasionally, a file of 7-8MB manages to succeed, only to fail on subsequent attempts.

Below are key lines of code with unnecessary details removed. The URL is a signed temporary PUT request that successfully passes the OPTIONS preflight call preceding the PUT request. The content-type header is crucial as it is part of the signing process for the URL.

xhr = new XMLHttpRequest()
xhr.upload.onerror = (e) ->
  console.log(xhr)
  console.log(e)
xhr.onerror = (e) ->
  console.log(xhr)
  console.log(e)
  true
xhr.open('PUT', url)
xhr.setRequestHeader('content-type', file.type)
xhr.send(file)

I have experimented with different files containing various sizes and extensions, but there doesn't seem to be a discernible pattern apart from the file size. To address this, I increased timeout values and tried to handle abort and timeout events, albeit without success.

Upon encountering the error, no decisive information is found in the event, xhr, or xhr.upload properties explaining the halt in transmission.

In Chrome tools, the failed attempt is displayed as a PUT request with status '(failed).' The error event indicates type="error" without further context, while the xhr object showcases minimal data at that point.

If anyone has any insights or unconventional suggestions to offer, your input would be greatly appreciated. Thank you.

Answer №1

Perhaps the issue lies not with the ajax request, but with the server configuration. It is essential that your server allows for file uploads of up to 1Mb.

If you are using PHP, make sure to adjust the upload_max_filesize and post_max_size settings in your php.ini file.

/* Here is an example */
upload_max_filesize = 10M
post_max_size = 10M

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

Safari: The onbeforeunload event

Welcome! To experience the Leave | Stay confirmation box on your page, please make sure you are using Safari 10. I am currently facing an issue with getting the confirmation box to display properly across different browsers. To begin, please visit and l ...

The issue with flexslider not functioning properly arises when used in conjunction with ajax Magnific popup

Having trouble integrating flexslider into magnific popup as the script inside the popup is not functioning properly. The magnific popup is being loaded using the wordpress function wp_enqueue_script(): jQuery(document).ready(function($){ $(&apo ...

RxJS BehaviorSubject allows you to retrieve the current value or obtain a new one depending on a specific condition

I am managing a subject that consumers subscribe to: private request$: Subject<Service> = new BehaviorSubject(null); Upon initialization, my components utilize this function: public service(id: number): Observable<Service> { return this. ...

Getting the expanded row columns values in a RadGrid when using the onHierarchyExpanded event

Here is the code for my RadGrid: <telerik:RadGrid ID="ProductRanges_Grd" ShowHeaderWhenEmpty="true" runat="server" AutoGenerateColumns="false" Width="100%" Height="250px" ShowHeader="true" Visible="false" ...

Generate a unique identifier for the HTML content

Is there a more efficient way to assign unique id tags to certain words using vanilla javascript? For example: <p>All the king's horses ran away.</p> For instance, "All" would have the id "term1", "King's" would have "term2", and ...

Switch up the query parameter in the current Vue router route

I am working on appending attribute parameters to a URL using the following code snippet: this.$router.push({ query: Object.assign({}, this.$route.query, { attributes: this.encodedAttributes() }) }); However, I have noticed that when I call this method fo ...

Display a button in a single row table

Here is my table markup: <table class="table table-condensed"> <thead> <tr> <th>id</th> <th>task</th> <th>date</th> </tr> </thead> ...

"The TextInput component in ReactNative is preventing me from inputting any text

Experiencing issues with the iOS and Android simulators. Upon typing, the text disappears or flickers. I attempted initializing the state of the texts with preset values instead of leaving them empty. However, this caused the TextInput to stick to the ini ...

Is it advisable to present a distinct version of my Ajax-powered GWT website to search engine spiders?

Currently in the process of constructing a website (using GWT) that heavily relies on AJAX functionality. Given this, is it advisable to develop a separate 'view' specifically for search engines? One idea that comes to mind is creating a distin ...

How to make Angular resolver and component share an injected service?

In my products list component, I have a table displaying various products. Since there is a considerable amount of data, I implemented a resolver to prevent the user from being directed to the page until all the data is loaded. The resolver currently utili ...

- Discover the steps to displaying an ajax response in a stylish fancybox iframe

Currently, I am facing an issue with displaying cart (viewcart.jsp) in an iframe using fancybox when adding a product to the cart. Here is what I have attempted so far. How can I effectively pass the ajax response to the iframe? $(document).ready(functio ...

creating curved lines in three.js

I'm looking for assistance in creating a globe using three.js where I can project arcs representing exports and imports between countries. I have a basic globe set up, but I need guidance on the following: 1. How to use country shape files instead of ...

Steps to Verify if Cookie is Turned Off in a Next.js Application

I have encountered an issue with my Next.js App. It seems to be functioning properly until I disable cookies in the browser. Is there a way for me to determine if cookies are disabled in the browser and display a corresponding message? I attempted to check ...

AngularJS radio buttons are unable to be selected in a simplistic manner

I have implemented a dynamic list display using HTML radio buttons. Here is the code snippet: <html> <head> <script src="angular-v1.5.5.js"></script> </head> <body> <div ng-app="myApp" ng-controller=" ...

Two consecutive instances of the outcome recorded in the ajax table

I am trying to add data to a table, but one of my results is appearing twice. Here is the JSON response I received: groupname […] 0 {…} survey_id 2 group_name DEMO 1 {…} survey_id 1 group_name TEST This is what my AJAX success function ...

Refresh the webpage source code for an AJAX request

When using AJAX calls on a page, I have noticed that the page source remains unchanged. This can be problematic if a user performs forward/backward operations in their browser, as the browser will display the original HTML code instead of the updated conte ...

Tips for attaching event listeners to custom elements

Let's suppose I create a Vue component called Checkbox.vue that contains the following code. <template> <div class="checkbox"> <input id="checkbox" type="checkbox"> <label for="checkbox">Label</label> ...

What steps should I take to ensure that the array yields the correct output?

Why is my code not creating an array of [0, 1, 2] when I pass the number 3 as a parameter? const array = [0]; const increment = (num) => { if (num > 0) { increment(num - 1); array.push(num); } return; }; console.log(array); incremen ...

My function doesn't seem to be cooperating with async/await

const initialState={ isLoggedIn: false, userData: null, } function App() { const [state, setState]= useState(initialState) useEffect(()=>{ async function fetchUserData(){ await initializeUserInfo({state, setState}) // encountering an ...

Ways to verify if a string contains a specific template literal in javascript

I attempted to verify this by using the str.includes('${') method as a straightforward approach, but it did not produce the expected results. I found that it also returned strings that didn't contain the specified characters. For instance, ...