Angular allows for easy downloading of files from a server by implementing a

I am attempting to retrieve a file from the server using REST in JAVA and pass some parameters. Although I have had success with the FileSaver.js library, it is not functioning properly in Safari 8. How can I go about downloading the file in Safari? I have come across solutions like angular http get, but that seems limited to Google Chrome and does not allow passing parameters to the HTTP GET request. My backend is implemented in JAVA with Spring MVC.

Answer №1

Handling file serving on the backend:

@RequestMapping(value = "/fileService/temp/{temporalLink}", method = RequestMethod.GET)
public ResponseEntity<byte[]> getFileByTemporalLink(@PathVariable @NotNull String temporalLink) {

    byte[] fileContent; // obtain file content
    String fileName; // determine file name
    String mediaType; // identify media type

    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.parseMediaType(mediaType));
    headers.setContentDispositionFormData("attachment", fileName);
    return new ResponseEntity<>(fileContent, headers, HttpStatus.OK);
}

Requesting the file on the front-end:

Within the controller:

 $scope.exportProductToPdf = function (someParams) {    
        getFileDownloadLink(someParams).then(function (response) {
                $window.location.href = '/fileService/temp/' + response;
            });
        };

// somewhere in the code

var getFileDownloadLink = function(someParams) { 

     //perform promise work to find the requested file
     // ultimately resolve the filename 

    return $q(function(resolve, reject) {
        //work...
        resolve("filename.png");

    });

}

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

Is purchasing a Twilio phone for sending SMS messages a good idea?

As part of my testing process, I have implemented this code for sending SMS messages. Everything is working fine so far, but I have a question regarding the necessity of purchasing a Twilio phone number to input into the "from" field. I intend to send real ...

Rails application encounters issue where CKEditor is removing style elements from span classes

In my current setup using Rails 4.1.4, Ruby 2.1.2, and CKEditor 4.1.1 integrated with Rails Admin, I am facing an issue. Whenever I enter text in the CKEditor text area and apply a font or font size, it saves successfully. However, upon viewing the content ...

Day Change Triggers React [Native] View Update

I've been working on a React Native component that needs to update itself when the day changes, regardless of user interaction. Is there another method besides using setInterval for this task? If I use setTimeout in my viewDidLoad function with the n ...

Create a JSON object that organizes a collection with indexed items

Is there a library available that can generate a JSON object where a collection is represented as a set of numbered items? For example, when using the GSON library with a class like this: `class Bus { List<Passenger> passengers; ...

Is it possible to horizontally center an auto-fill grid using only CSS?

I would like to fill my page horizontally with as many blocks as possible and center the result. My goal is to have a grid that can resize when the window size changes: wide window xxx small window xx x Is it possible to achieve this without using Java ...

Prevent the left border from displaying on a link that wraps to a new line

Excuse me, I am facing an issue with a pipe separator in my subnav bar between links. The problem is that the first link on a new line retains the left-border that should be disabled. How can I prevent this border from appearing on the first link of a new ...

Ways to trigger Bootstrap modal through a PHP GET call

I have been searching for a solution to create a modal similar to this one, but I haven't found anything yet. My requirement is that when we pass true in a GET request, the modal should be displayed. Otherwise, if there is no value specified in the $ ...

Tracking time in seconds and milliseconds with a stopwatch

Greetings! I am currently working on a reaction test to measure how quickly users react, and I seem to be struggling to find the necessary resources. I am curious about creating a basic stopwatch in seconds and milliseconds that can be triggered later by a ...

Establish a seamless UDP connection using JavaScript and HTML5

Is it feasible to establish a direct two-way connection with a UDP server using javascript/HTML5 (without node.js)? While WebRTC is an option, my understanding is that it does not support sending datagrams to a specific server. I am primarily focused on c ...

Challenges arise when attempting to integrate the jquery plugin (jlembed) due to conflicts with namespaces

I've been struggling to make jlembed work, but I keep encountering errors in the Chrome debugger. I've tried all of the solutions mentioned in THIS document with no success. Can someone guide me on the correct way to include jQuery and a jQuery p ...

Avoid running old JavaScript code when using turbolinks in conjunction with highcharts library, specifically LazyHighCharts

Utilizing turbolinks 5 and rails version 5, along with the latest Highcharts has been causing me some issues. T LazyHighCharts offers a solution for Turbolinks 5 by encapsulating chart building javascript within (function() { document.addEventListe ...

Searching for the function scope across modules - where could it be?

Consider the following scenario: include.js module.exports = function() { ... return { func: function(val) { return Function('return ' + val + ';'); } } }() running.js var outer = function() ...

What are some ways to utilize an Object that includes an array like this?

When working on a method similar to System.arraycopy in the Java library, I encountered an issue with using an object as an array. The problem arose when arr2 required an array, but java.lang.Object was found instead. Here is the code snippet: public st ...

Generate a dynamic kendo dropdown with data sources assigned in separate methods

Creating a kendo dropdown list dynamically based on the number of received id's is presenting a challenge. A method has been implemented to loop through each id and generate a corresponding dropdown with that id. These dropdowns are not all generated ...

jquery logic for iterating through all elements in a select menu encountering issues

In search of a solution to iterate through all options in a dropdown list using code, comparing each to a variable. When a match is found, I aim to set that particular value as the selected item in the dropdown and then exit the loop. Here's what I&ap ...

Issues with the controller not functioning properly in AngularJS version 1.3

Utilizing one controller in two different sections of a page, I am using an alias for the controller using the "controller as" syntax. However, after updating to Angular 1.3.15, this method no longer works. Below are links to fiddles demonstrating the issu ...

Issue with Node.js MongoDB collection.find().toArray not returning results

Despite coming across questions similar to mine, I struggled to resolve the issue independently. Within my '../models/user' model, my goal is to retrieve all users and store them in an array, which will then be returned to the controller for fur ...

Importing or loading a JavaScript file in Vue.js is a crucial step

I'm in need of some assistance. I've been attempting to load my javascript file and listen for changes on the checkbox when it's clicked to show or hide a password. However, I can't seem to get it to work. I've tried everything I c ...

Ways to take an item out of your shopping cart

Do you have any ideas on how to handle cart redirection in JavaScript? My specific request involves a cart with a function that removes products. What approach should I take to redirect to the main page if the cart becomes empty? Here is the delete produc ...

End the child process.execution after a specific amount of time

I have been searching for information on child process waiting time or response waiting time, but I haven't found anything useful. I'm in need of something like that, so I hope someone can assist me. When I look at the code below, I am printing ...