0

I am created project Ionic with Sharepoint,

I have a stored pdf, xls, doc, etc.. file in list, I have a actual path of a file URL, I am create documents Gallery in my app with download option, when i'm click download icon i have to download a that particular document.

I have tried

file trasfer plugin

i can't achieve pls help me to solve this problem.

here my tried code.

file trasfer way:-

 this.download("sample","https://abcd.sharepoint.com/samplesite/Shared Documents/sample.pdf");

 download(fileName: string, filePath: any) {
        const url= encodeURI(filePath);
        const fileTransfer: FileTransferObject = this.transfer.create();      
        fileTransfer.download(url, this.file.externalRootDirectory + fileName, true).then((entry) => {
          //show toast message as success    
        }, (error) => {
          //show toast message as error        
        });
    }

pls give some idea to download a file. Is there any other way is available to download a file using url in ionic3?

Karnan Muthukumar
  • 1,843
  • 1
  • 8
  • 15

1 Answers1

0
$ ionic cordova plugin add cordova-plugin-file-transfer
$ npm install --save @ionic-native/file-transfer

function

const url = 'https://abcd.sharepoint.com/samplesite/Shared Documents/sample.pdf';
  fileTransfer.download(url, this.file.dataDirectory + 'sample.pdf').then((entry) => {
    console.log('download complete: ' + entry.toURL());
  }, (error) => {
    // handle error
  });
Grenoblois
  • 503
  • 1
  • 5
  • 19
  • Thanks for your quick reply. this.file.dataDirectory once i use it this path i can't view the file in my mobile. – Karnan Muthukumar Jun 08 '18 at 12:35
  • otherwise, Use the file path this.file.externalRootDirectory i find the file. But once i am open it. It shows "The file appears to be corrupted" popup appeared – Karnan Muthukumar Jun 08 '18 at 12:35