Ionic 2 download file in assets folder

I try to download file in application directory of project but it gives error : URI not supported by CordovaResourceApi

Elaborate about this error e.i what is your code like?

code is :
var url=', cordova.file.applicationDirectory + “ebooks/” + fileName).then((entry) => {
console.log('download complete: ’ + entry.toURL());
this.url = entry.toURL();‘download complete’, ‘1500’, ‘bottom’).subscribe(
toast => {

    }, (error) => {
          console.log('download fail  : ' + JSON.stringify(error));'fail to download ', '1500', 'bottom').subscribe(
        toast => {
      // handle error

and error is {“code”:1,“source”:“",“target”:“file:///android_asset/ebooks/”,“http_status”:200,“body”:null,“exception”:"URI not supported by CordovaResourceApi: file:///android_asset/ebooks/”}

Try this:

Use ionic file and file transfer native plugins and import in your component file

import { FileTransfer, FileTransferObject } from '@ionic-native/file-transfer';
import { File } from '@ionic-native/file';

And now you use this Cordova plugins like this,

var URL = encodeURI('’);

var targetPath = this.file.documentsDirectory + 'ebooks/' ;

const fileTransfer: FileTransferObject = this.transfer.create();,targetPath+fileName,true)
          .then((entry) => {
               console.log('download complete: ’ + entry.toURL());
          }, (error) => {
               console.log('download fail: ' + error);

I also use file transfer native plugins it works when using documentsDirectory but give error for applicationDirectory and I want to download it in applicationDirectory (asstes folder) of project

Hi, @demokumar

because applicationDirectory is read-only,

yes I know but for display pdf using pdf js it required path of file from assets folder :frowning: so how I do this ?

have you found a solution? I have the same problem

The assets folder is virtual. It doesn’t exist, so you cannot write anything to it at runtime. The only way to get anything in there is to bundle it into your application at build time.

Thank you for your answer
I am using a plugin (PDFTron) which only opens files from the assets folder
in my application I would like to download the files before opening them
i even tried to open the file which is on the server using its url, but i have the error CORS policy: No ‘Access-Control-Allow-Origin’

That needs to be resolved on the server side.