Download File from URL

Hi I have connected my Ionic 2+ app to Amazon S3. In my app when I want to download a file my backend delivers a unique pre-signed URL generated from my S3. Looks something like this:

My question is how do I download the file programatically through my component once I have the url? I have tried so far without luck:, '_blank');


getFile(url: string): void {
    .subscribe(blob => {
      console.log('Blob', blob);
      var data = new Blob([blob], { type: 'text/csv' });
      var url= window.URL.createObjectURL(data);;
    }, error => {
    console.log('Get File http');

Ok so further to above I sort of got it working for my iOS and android app by implementing cordova file transfer. However it does not work in a normal web browser as file transfer is mobile only. My code below., 'file.pdf').then((entry) => {
      console.log('download complete: ' + entry.toURL());
    }, (err) => {
      // handle error

However it opens the file in a new window. Is there anyway to actually give the user the option to save as? Also any work around to also work in a normal browser ie progressive web app?? Thanks in advance for any help on this.


how did you achieve it ? can you please elaborate and what all plugins you used here? for me it says ‘cannot find URL name’

Did you figure out how to make it work for normal browser(pwa) yet?

Not on the frontend but instead I had my backend dev to setup aws s3 to download as an attachment by apply content-disposition=>content as part of the file’s meta data. This way when I click on the href link it automatically downloads.

This article might help:

1 Like