copyFile from assets


How can I copy file from assets folder to File.dataDirectory via cordova-plugin-file on android?

this.file.copyFile('assets', 'data.json', this.file.dataDirectory, 'data.json');

The file exists and I can read it via Http data service:

import {Injectable} from '@angular/core';
import {Http, Response} from '@angular/http';
import 'rxjs/Rx';

export class DataService {

   constructor(public http:Http) 
   getData() {
    return this.http.get('assets/data.json')
        .map((res: Response) => res.json());

What I am doing wrong? Thanks!


What error are you getting?


I would be surprised if this were possible, because the file doesn’t really exist from the perspective of the OS. Things under assets are bundled up into a virtual filesystem that lives inside your app bundle. I think the only way OP could achieve this is to read via HTTP and write to a new file.


I get cordova_not_available


That error will go away when you build into an actual device. The cordova-plugin-file plugin uses the cordova.js library that is not included when you build for browser. So test your code in your device and try again.