The readAsDataURL() method in FileReader is unable to process a large 24 MB PDF file in TypeScript

const reader = new FileReader(); 
reader.readAsDataURL(file);

When utilizing the readAsDataURL method, smaller files (under 5mb) are read and uploaded successfully. However, issues arise when attempting to upload larger files (24MB), as the filereader.result returns null in Internet Explorer. This functionality does work correctly in Chrome.

Answer №1

Avoid using the FileReader API and instead, directly stream the file object for better efficiency.

var config = { headers: { 'Content-Type': undefined } };

$http.post(url, file, config)
  .then(function (response) {
    var data = response.data;
    var status = response.status;
    var statusText = response.statusText;
    var headers = response.headers;
    var config = response.config;

    console.log("Success");
    return response; 
}).catch(function (errorResponse)
    console.log("Error");
    throw errorResponse;
});

The XHR Send Method is capable of streaming file objects as they are a type of Blob, eliminating the need to load the entire file into memory.

It is crucial to set the content type header to undefined so that the XHR send method can properly handle it. Otherwise, AngularJS will default to application/json.

Refer to AngularJS $http Service API Reference for more details.

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

The orderBy feature in AngularJS does not seem to be functioning properly when using a

Recently, I have developed a custom function to determine the "fromNow" value using Moment and now I am looking to organize the data based on this function's output. I aim to place the Table Element at the top where the Days from Now are fewer. In t ...

Enhance Your User Experience with the Onsen UI Bluetooth Extension

Trying to integrate a Bluetooth plugin using Onsenui in Monaca IDE, but consistently encountering the error message: "bluetoothSerial not found." Looking to develop a service that necessitates the Bluetooth Serial plugin. Planning to simply utilize a .is ...

Utilizing the same code for multiple UI-Select components within an Angular application

Is there a way to efficiently reuse code when dealing with multiple ui-select elements in an Angular app, each connected to different remote APIs to populate options? After reading about AngularJS Wrapping a ui-select in a custom directive, I was inspired ...

Angular 5 is unable to access the value of a form control when the name attribute is not specified

Snippet of HTML code: <li class="dropdownfilter" *ngIf="this.arr.inclues('Male')" (click)="getValueGender('Male',1,)" [(ngModel)]="M"><a>Male</a></li> I encountered the following error: ERROR Error: No value a ...

Avoid circular dependencies in Angular 6 to ensure proper association between modules

When working with TypeScript, how should I handle the scenario where Cat has an owner: Person Person owns a pet: Cat Cat import {Person} from './person' export class Cat { owner: Person constructor(){ this.owner = new Pers ...

Adding an image to a Select Option label in React: A simple guide

As a newcomer to React, I am experimenting with creating a drop-down menu that includes images in the labels. My approach involves using a function to gather values from a map and construct an id: label pair to display as options in the drop-down. Both the ...

Ways to retrieve API data utilizing the $http service

My current project involves using the Riot Games API, but this example utilizes the REST Countries API. You can find more information at The technology stack I am using is MEAN.IO and below you will see a snippet of my code: test.html <html ng-app="l ...

A guide on clearing the selected value in a dropdown menu with Angular.js

Can someone assist me with setting the drop-down value to blank after completing an action in Angular.js? Below is my code explanation: <div style="height:270px; overflow-x:hidden; overflow-y:scroll;" ng-show="viewOrderTable"> <div class="table-r ...

The art of Angular JS dependency injection made easy

My goal is to inject a javascript object into my controller using the "value" approach. Initially, I successfully created and injected a value object named "defaultInput" with a data value of 5 within my Angular module: //define a module var mainApp = ang ...

Introduction to Monaca Onsen UI: A Step-by-Step Guide for

Searching for comprehensive walkthroughs on Monaca Onsen UI has proven to be a challenge. Many available tutorials are geared towards advanced users, making it difficult for beginners to follow along. The mix of Angular, jQuery, and plain JavaScript furthe ...

The declaration file for the 'express' module could not be located

Whenever I run my code to search for a request and response from an express server, I encounter an issue where it cannot find declarations for the 'express' module. The error message transitions from Could not find a declaration file for module & ...

Tips and tricks for sending data to an angular material 2 dialog

I am utilizing the dialog box feature of Angular Material2. My goal is to send data to the component that opens within the dialog. This is how I trigger the dialog box when a button is clicked: let dialogRef = this.dialog.open(DialogComponent, { ...

UI-grid: Triggering a modal window from the filter header template

Is there a way to create a filter that functions as a simple modal window triggered by a click event, but can be displayed on top of a grid when placed within the filterHeaderTemplate? I have encountered an issue where the modal window I created is being ...

AngularJS DataGrid export options

Utilizing the angular-datatable plugin, complete with export buttons. You can see an example here: vm.dtOptions = DTOptionsBuilder.fromSource('data.json') .withDOM('frtip') .withPaginationType('full_numbers') // ...

Issue with retrieving data from dataTransfer on 'drop' event due to undefined value

I'm currently working on implementing Drag & Drop functionality using AngularJS directives. Here's the concept I am trying to execute : Check out my codePen However, I keep encountering an error saying 'getData' is undefined. Th ...

How to implement angular 2 ngIf with observables?

My service is simple - it fetches either a 200 or 401 status code from the api/authenticate URL. auth.service.ts @Injectable() export class AuthService { constructor(private http: Http) { } authenticateUser(): Observable<any> { ...

Sharing AngularJS data between controllers through a service is not possible

When creating my service : .factory('patientListBarService', function() { var data = { pages: 0, total:0 }; return data; }) In my first controller: .controller('patientCtl', ['$scope', '$htt ...

Troubleshooting the problem of redirecting a website to www on IIS 10 (Windows Server 2019)

I have a React website running on port 3000. Currently, the website can be accessed with and without the www prefix, causing duplicate SEO issues. I want to ensure that the website always redirects to https://www.pess.org.ua. web.config <?xml version=& ...

"Combining the elegance of Jade with the power of Angular

Just the other day, I delved into the world of Jade and have prior experience working with AngularJS. During my exploration, I noticed a trend of people combining Jade with AngularJS. From what I gather, when utilizing AngularJS, we can leverage its feat ...

Refreshing the page is not necessary when updating cell data in ui-grid

I have set up a user interface grid to display information about a collection of news stories. The grid includes options for editing, deleting, and creating new stories in the final column. While everything appears to be functioning correctly - I can succ ...