Can't load downloaded json data using http.get() method

Hi,
I am using file and file transfer plugin to download a zip file and ionic zip plugin to extract the downloaded zip.
The zip file contains images and many json files. After extracting the zip file, I uses httt.get() method to get the locally downloaded json files. But I am getting the following error:

Failed to load file:///data/user/0/com.newzipper.com/files/edition1/563177.json: Cross origin requests are only supported for protocol schemes: http, data, chrome, https.

My code is as follows:

this.unzip_file_path = navParams.get('zip');
	this.file.createDir(this.file.dataDirectory, 'edition1', true).then((data) => {
		this.zipper_path = data.nativeURL;
		this.zip.unzip(this.unzip_file_path, this.zipper_path).then((result) => {
		},
		err => {
			console.log(err, "err");
		});
	});
	this.file.checkDir(this.file.dataDirectory, 'edition1').then((data) => {
		this.file_deleted = 0;
		this.loadData();
	},
	err => {
		console.log(err,"error 1");
	});
	
}
loadData(){
	var link = this.file.dataDirectory + "edition1/editionindex.json";
	this.file.checkFile(this.file.dataDirectory , "edition1/editionindex.json").then((fileexist) => {
		this.http.get(link).map(res => res.json()).subscribe((data) => {
			console.log(data, "data");
		},
		err => {
			console.log(err, "err");
		})
	},
	err => {
		console.log(err, "error in file");
	});
}

Any suggestion is appreciable.

Thanks

did you find a solution? I have the same problem

PS: on android

change “this.file.dataDirectory” to other location.
Give it a try…

thanks for answer but it was something else

I forgot that I use the ionic-webview and it handles file:/// different.

They even write it in there doc but I forgot about it:
If you’re working with local files (text files, images, videos), you’ll need to make sure that the path of file does not have file:// in front of it.

https://blog.ionicframework.com/wkwebview-for-all-a-new-webview-for-ionic/

1 Like

Glad that you found it. Cheers!!