Loading extremely sizable images using AngularJS

My goal is to load a very large image (from the perspective of my web app), weighing around 10-20 MB using an AJAX call.

I am utilizing angular resource:

'use strict';

angular.module('myApp')
.factory('Picture', function ($resource, DateUtils) {
    return $resource('api/pictures/search', {}, {
        'get': {
            method: 'GET',
            transformResponse: function (data) {
                data = angular.fromJson(data);
                return data;
            }
        }
    });
});

The response JSON I receive contains Base64-encoded image data in one of the fields, similar to this:

{title: "some title", picture: "<Base64-encoded image data>", ...}

After a successful response, I take response.picture and place it inside an <img>:

<img ng-src="{{pictureSrc}}" class="img-responsive center-block" alt="Picture">

like so:

Picture.get({id: resourceId}, function(response){
        $scope.pictureSrc = 'data:image/png;base64,' + response.picture;
    });

This method works fine until the image size exceeds 10MB, leading to JSON deserialization failure.

If I modify the Content-Type of the response to image/png, and only return the image data, the application still encounters errors, likely originating from angular.js.

Recognizing the limitations of my current approach, I believe it's necessary to reconsider how these images are fetched rather than attempting to resolve this specific issue.

Which brings me to my question: Is there a reliable way to fetch large images (up to 20MB) with an AJAX call using AngularJS?

UPDATE: I am utilizing FF 42.0 and Chrome 45.0.2454.101 (64-bit), aiming for compatibility across major browsers including IE8 (although that might require a separate discussion)

UPDATE 2: Additional Information: FF freezes when I solely return image data without any JSON formatting in my response. With JSON, it shows this error message:

JSON.parse: unterminated string at line 1 column 1572865 of the JSON data
.

Answer №1

The size of HTTP responses (JSON, for example) is not limited. However, the capacity of the browser's memory can be a constraint.

If the object parsed from the JSON response is consuming excessive memory, it could lead to unresponsiveness. It might be beneficial to test your application with varying data sizes to ensure its proper functionality.

I trust this information proves useful!

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

Analyzing DynamoDB Query

I am on a mission to recursively analyze a DynamoDB request made using the dynamo.getItem method. However, it seems that I am unable to locate a similar method in the DynamoDB SDK for Node.js. You can find more information about DynamoDB SDK at http://do ...

Guide for generating a JSON array with Jackson library

I am currently working on generating a json response for a report. Here is an example of the data structure I need: var data = [ ["", "Kia", "Nissan", "Toyota", "Honda"], ["2008", 10, 11, 12, 13], ["2009", 20, 11, 14, 13], ["2010", 30, 15, 12, 13] ...

Advantages of optimizing NodeJS/TypeScript application by bundling it with webpack

Currently, I am working on a Node/Express application and I am interested in incorporating the most recent technologies. This includes using TypeScript with node/Express along with webpack. I have a question: What advantages come with utilizing webpack t ...

Animating rows on a gridview with Ajax

Is it possible to fade/change the row color from red back to white on a gridview using asp.net ajax animation when a linkbutton is clicked? And can this be done in the code-behind in c# (specifically in the linkbutton_click event)? ...

Android Browser is experiencing issues with returning JSON data consistently after making an AJAX call

When I make an ajax call to an API for JSON data, everything works perfectly with other browsers. However, when using the Android Browser, the response seems to act strangely. I have added a console log using weinre to catch the returned data. Can anyone h ...

"I am eager to showcase the text upon pressing the Enter key, implementing an Immediately Invoked Function Expression

My input text box is supposed to store and display the output in an unordered list format when I hit enter. The function works fine without IIFE using onclick event, but it's not working with IIFE. Can anyone assist me with this issue? <html> ...

What is preventing me from installing react-router-transition on the 1.4.0 version?

$ npm install -S <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8dffe8eceef9a0ffe2f8f9e8ffa0f9ffece3fee4f9e4e2e3cdbca3b9a3bd">[email protected]</a> npm ERROR! code ERESOLVE npm ERROR! Unable to r ...

Navigating to the next page on a dynamic component in Angular 5 by

I'm uncertain if this scenario is feasible, but I have a page that fetches a list of items from an external API. There are currently 5 elements on the page, each acting as a link to its individual dynamically generated page through query strings. For ...

Separate a series of JSON blocks separated by commas (excluding commas within each JSON block)

Here's an interesting situation. I'm faced with a challenging input string that consists of a series of JSON blobs separated by commas. For example: string input = "{<some JSON object>},{JSON_2},{JSON_3},...,{JSON_n}" My task is to conver ...

Unable to pass an event parameter using my this.handleChange function in react-native

Encountering an issue with the error message "undefined is not an object (evaluating 'event.preventDefault)" It appears that I am unable to pass an event parameter to the handleChange function in my child component, which is being rendered in the par ...

Troubleshooting: Angular 6 Renderer2 Issue with Generating Dynamic DOM Elements for SELECT-Option

Currently, I am attempting to dynamically create a select option using Renderer2. Unfortunately, I am facing difficulties in creating the <Select></Select> element, but I can confirm that the <options> are being successfully created. Due ...

Using JavaScript import may encounter issues when trying to access the same file or a different file

When importing something and using it, there are certain scenarios where it may not work as expected. For example: <html> <body> <button onclick="foo()">Click Me</button> </body> <script type="module"> ...

Learning how to dynamically update a value in Angular based on user input

My goal is to dynamically change the output value based on user input using Angular. I have successfully implemented the functionality to increment the value, but unfortunately, when the input changes, the outputed value remains static. Below is my curren ...

Utilizing PHP, AJAX, and MySQL for dynamic checkbox filtering and seamlessly switching between logical operators AND/OR

I'm attempting to implement a search filter using checkboxes. Depending on which checkboxes are selected, the `SELECT` query will need to incorporate both `AND` and `OR`. Below is the HTML code for the filter: <table> <tr ...

Trigger an action in the clean-up function of useEffect

I am facing an issue with a form component in a Material UI <Tab /> where users can update their address information. The data is fetched from the API using redux-thunk, and the form fields are pre-filled with server data before the update occurs. h ...

Retrieve the response text from a jQuery.get() call and return it

Attempting to achieve the following: var msg = $.get("my_script.php"); Expecting msg to be assigned to the text returned by my_script.php, which should be the responseText of the jqXHR object. However, it seems that msg is consistently set to "[object XM ...

ways to halt a noise once an animation is complete

I don't have much experience with coding in general, but somehow I've made it this far. Now I'm stuck on the final piece of the puzzle. This is related to a Twitch alert that I'm setting up through 'Stream Elements'. The iss ...

"Capturing the essence of your online presence: The

I recently completed a website for my Students Organization, which includes a special page dedicated to recognizing the individuals who helped organize our activities. Each member is represented with a photo on this page, sourced from their Facebook profil ...

Unable to locate the method within User.js

I'm encountering an issue with a method in express. I've included the error code below index.js app.post('/login', function (req, res) { User.findOne({ email: req.body.email }, function (err, user) { if (!user) { ...

Unraveling the Depths: A Guide to Parsing Nested JSON Arrays of

Initially, I am aware that there have been similar inquiries raised before. Out of all the queries, I stumbled upon one that provided some assistance: , although I am encountering difficulties while trying to implement the suggested solution in my own situ ...