Obtaining zip files using AngularJS

Upon entering the following URL in my browser, I am prompted to download a file:

My goal is to download this file using an AngularJS HTTP request.

I have created a factory for this purpose, but unfortunately, the download is not successful.

Even though the request receives a 200 status code, the loader continues spinning in Firebug.

app.factory('File', ['$http','GENERAL_CONFIG', function($http, GENERAL_CONFIG) {
    var API_URL = GENERAL_CONFIG.BASE_API_URL;

    API_URL = API_URL + 'filetransfer/';

    return {
        download: function(filename, type,successcallback, errorcallback){
            var apiurl = API_URL + filename + '?type='+type
            $http.get(apiurl,{
                headers: {
                    "Content-Type": "application/x-download;"
                }
            }).success(successcallback).error(errorcallback);
        }
    }
}]);

Answer №1

Although this post is dated, I wanted to provide an answer for potential current requirements.

If you are making an http request, make sure to include an extra header. Specify the responseType as "arraybuffer".

You can then convert the response into a blob object and send it to the callback like this: URL.createObjectURL(new Blob([response]));

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 functionality of the submit form is encountering issues upon integration of Ajax requests

Hello everybody! I am currently creating a dynamic form for editing specific classes, but I am facing an issue with the ajax call not working. Below is the HTML code for the form: <form id="userDataForm" name="userDataForm" th:acti ...

How can I resolve the issue of encountering the "Modal dialog present: If you navigate away from this page, any unsaved changes will be lost" message while using Internet Explorer with

Here's the code snippet I'm working with. While it successfully removes the alert box, it throws an error in the console: Exception in thread "main" org.openqa.selenium.UnhandledAlertException: Modal dialog present: If you leave this page, any c ...

When the parent div contains at least four divs, show the scroll arrow containers

In my code, there is a parent div that holds multiple child divs. If the number of child divs within the parent div exceeds 4, I want to show the scroll arrow containers. If it's less than 4, then those arrow containers should not be displayed. The ...

Ways to create two distinct "on click" actions for a single image to execute two distinct tasks

Clicking on an image will open a slider showing all images before filtering. Once filtered, only the selected images will be displayed in the slider. <div class="gallery row" id="gallery" style="margin:0;"> <!-- Grid column --> <div ...

Submitting an ASP.NET page should not cause the entire page to post back

My ASP.NET webpage currently has a Submit button that, upon clicking it, triggers my code to run and the page then refreshes, resulting in a full reload of the entire page. I am looking for a solution to prevent this page reload. Would implementing AJAX b ...

Simplify nested JSON data

I'm struggling with a JSON object that looks like this: const people = { name: 'My Name', cities: [{city: 'London', country: 'UK'},{city: 'Mumbai', country: 'IN'},{city: 'New York', country: ...

Navigating to lower levels of JSON data in JavaScript instead of starting with the top level

Using a microservice, I fetch multiple sets of JSON data and display them on a Vue.js-powered page. The structure of the data is as follows: {"data":{"getcompanies": [ {"id":6,"name":"Arena","addr ...

How can I apply angular ng-repeat filter with specific criteria in mind?

I am currently developing an angular application and I need to present customer data in a table using ng-repeat. While I have successfully added ng-filter for searching the results based on user input, I am now looking to incorporate checkboxes to further ...

Executing MySQL queries synchronously in Node.js

When working with NodeJS and mysql2 to save data in a database, there are times when I need to perform database saves synchronously. An example of this is below: if(rent.client.id === 0){ //Save client connection.query('INSERT INTO clients (n ...

Issues encountered with the data-binding functionality of angular-froala 2.1.0 when used in conjunction with angular 1.1

At the moment, I'm immersed in a project that utilizes Angular 1.1.5. Unfortunately, upgrading Angular is off the table for now. Our goal is to integrate a feature-rich HTML5 WYSIWYG-editor, and we've settled on trying out Froala because it alig ...

What is the best way to utilize the $http service when a state change event occurs in AngularJS?

I am working with AngularJS and utilizing Ui-Router. In order to execute the $http service on each state change, I'm encountering an issue. When attempting to inject the $http service within the statechange event, a circular dependency error is thrown ...

Cypress - Mastering negative lookaheads in Regular Expressions

While experimenting with Cypress, I encountered an issue regarding a filter test. The goal is to verify that once the filter is removed, the search results should display values that were filtered out earlier. My attempt to achieve this scenario involves ...

Connecting to databases using AJAX technology

Here's something I've been pondering: When you invoke a script, like let's say makePage.php, by clicking on a button and triggering an AJAX request, do you need to create a new database connection? Even if there is already a connection estab ...

Tips for refreshing the <img> tag using a user image

I am currently designing a bootstrap webpage and trying to implement a feature where the user can input an image, which will then be displayed in a preview modal along with some text provided by the user. The modal is functioning correctly. Here is the co ...

When you add a new library using npm and it has a dependency on another existing library, it could potentially cause conflicts or issues with

After successfully installing a library, I am now looking to install another library that relies on the first one. I have some uncertainty about what will occur: The second library will utilize the shared library already installed for its functionality ...

What is the process for implementing a custom error when compiling Sass code with node-sass?

When using node-sass to compile my sass code, I am curious about the possibilities during the compilation process. To clarify, I am interested in creating custom rules and generating specific errors under certain conditions while compiling. ...

Converting an array of object keys into integers only can be done using JavaScript

Here is an array of objects with various nutrients and their values: [ {nutrient: "Energy", per100: "449kcal", per35: "157kcal", id: 6} {nutrient: "Fat", per100: "24.4g", per35: "8.6g", id: 1} {nutrient: "Saturated fat", per100: "4.5g", per35: "1.6g ...

Encountering an issue with React npm causing errors that I am unable to resolve

Hey there, I'm a newbie to React. After setting everything up, I encountered an error after running "npm start." Can anyone help me figure out how to fix this? Thanks in advance! Click here for image description ...

Passing Props from _app.js to Page in ReactJS and NextJS

I recently made the switch from ReactJS to NextJS and am encountering some difficulties in passing props from _app.js to a page. My issue lies in trying to invoke a function in _app.js from another page. In ReactJS, this process was simple as you could cr ...

Gather information from every user and display their user ID in an HTML table, allowing for updates through a button

Can anyone help me create a table like the one shown here: The table should fetch data from my firebase database. Here is the structure of my requests database: . I've been trying to modify some code I found in a previous question. However, as you c ...