Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not allowed to load local resource #183

Closed
macklus opened this issue Aug 6, 2018 · 34 comments · Fixed by #194
Closed

Not allowed to load local resource #183

macklus opened this issue Aug 6, 2018 · 34 comments · Fixed by #194

Comments

@macklus
Copy link

macklus commented Aug 6, 2018

Hi:

I using:

  • Ionic: 4.0.3
  • Ionic Framework: ionic-angular 3.9.2
  • Ionic image Loader: 5.0.5

when i try to load an image, i get error:

"Not allowed to load local resource: file:///data/user/0/MI_APP_ID/cache/image-loader-cache/-919523643", source: http://localhost:8080/ (0)

any hint about this problem ?

thanks in advance.

@Ross-Rawlins
Copy link

Got this same issue on android did you resolve it?

@Ross-Rawlins
Copy link

I only got this issue when using ionics latest webview which also causes issues with other plugins. I rolled back the webview and its working now.

@macklus
Copy link
Author

macklus commented Aug 7, 2018

How do you do that ?
Anyway, i hope problem can be solved, latest webview is better than old one

@mateusknob
Copy link

Having the same issue over here on a Android device (on browser works fine)

@mateusknob
Copy link

mateusknob commented Aug 7, 2018

setting the return type to base64 works!

this.imageLoaderConfig.setImageReturnType('base64');

it's not the best solution, but...

@macklus
Copy link
Author

macklus commented Aug 7, 2018

@mateusknob can this option be globaly configure ?

@mateusknob
Copy link

@ghost
Copy link

ghost commented Aug 21, 2018

You need to perform 2 actions to resolve.
a) install https://cloud.google.com/storage/docs/gsutil_install
b) browse to the home directory where you instal google cloud sdk (a) above > gsutil
c) Run in terminal > gsutil cors set cors.json gs://

If you want to logout from all the accounts run the following command

gcloud auth revoke --all
If you want to logout from a specific account then run the following command

gcloud auth revoke <your_account>
If you want to login with a different account, you can run the following command

gcloud auth login

Then

import { ImageLoaderConfig } from 'ionic-image-loader';
constructor(
private imageLoaderConfig: ImageLoaderConfig) {
 this.imageLoaderConfig.setImageReturnType('base64');
}

Ionic info

ionic (Ionic CLI)  : 4.0.5 
   Ionic Framework    : ionic-angular 3.9.2
   @ionic/app-scripts : 3.1.11

Cordova:

   cordova (Cordova CLI) : 8.0.0
   Cordova Platforms     : android 7.1.0

Ref: Documents :
a) https://firebase.google.com/docs/storage/web/download-files
b) https://cloud.google.com/storage/docs/gsutil_install

@ghost
Copy link

ghost commented Aug 21, 2018

@mateusknob - your solution worked with an extra research and more steps implemented as above, thanks!

@Shtibel
Copy link

Shtibel commented Sep 3, 2018

Can confirm.
The new ionic webview plugin is the cause for the problem.
The new plugin: cordova-plugin-ionic-webview @ 2.x seem unstable...

You can follow the issue I opened there:
ionic-team/cordova-plugin-ionic-webview#158

I downgraded back to cordova-plugin-ionic-webview@1.2.1 and all works grate.

Steps:

  1. uninstall webview
    ionic cordova plugins rm cordova-plugin-ionic-webview

  2. install old one:
    ionic cordova plugins add cordova-plugin-ionic-webview@1.2.1

  3. clean cordova
    cordova clean android

By the way angular-cropperjs is also not working with the new webview.

@macklus
Copy link
Author

macklus commented Sep 4, 2018

just for confirm, solution of @mateusknob is working ??
i do prefer do that before downgrade webview

@Shtibel
Copy link

Shtibel commented Sep 4, 2018

Hi @macklus
I can confim this is working for me

@macklus
Copy link
Author

macklus commented Sep 7, 2018

@Shtibel sadly, its not working for me.
can you please paste your package.json file to compare ?
thanks

@shriniwasb
Copy link

Hi,
Use this
window.Ionic.WebView.convertFileSrc(localFilePath)

@SmirnovM91
Copy link

Hi,
Use this
window.Ionic.WebView.convertFileSrc(localFilePath)

Where should I use it?

@shriniwasb
Copy link

Hi @SmirnovM91,

Cordova and Capacitor apps are hosted on a local HTTP server and are served with the http:// protocol. Some plugins, however, attempt to access device files via the file:// protocol. To avoid difficulties between http:// and file://, paths to device files must be rewritten to use the local HTTP server. For example, file:///path/to/device/file must be rewritten as http://://path/to/device/file before being rendered in the app.

For Cordova apps, the Ionic Web View plugin provides a utility function for converting File URIs: window.Ionic.WebView.convertFileSrc(). There is also a corresponding Ionic Native plugin: @ionic-native/ionic-webview.

Please check this below link
https://beta.ionicframework.com/docs/building/webview/

@ihadeed
Copy link
Member

ihadeed commented Sep 17, 2018

Is this still an issue with the latest releasE?

@flore2003
Copy link
Contributor

Yes, it is. I traced it down to the getCachedImagePath method in image-loader.ts. It checks the isIonicWKWebView getter, which in turn checks the isWKWebView getter, which only evaluates to true on iOS. When using Ionic on Android, the file URI is never transformed for Ionic and thus the error is thrown. I might be able to create a pull request later today, if you would be interested in having this issue fixed 🙂

@flore2003
Copy link
Contributor

There it is ☝️

@b1ueRa1n
Copy link

@Shtibel Thank you very much! The new ionic webview plugin is the cause for the problem.

@b1ueRa1n
Copy link

Yes, I had found another solution.

in .html
<img [src]="getTrustImg(imageSrc)" />

in .ts
private win: any = window;

getTrustImg(imageSrc){
let path = this.win.Ionic.WebView.convertFileSrc(imageSrc);
console.log(path);
return path;
}

@Sampath-Lokuge
Copy link

This is the version where it works for me on Ionic 3.9.2 app.

https://github.com/ionic-team/cordova-plugin-ionic-webview/releases/tag/v1.2.1

@borodatych
Copy link

borodatych commented Dec 20, 2018

import { normalizeURL } from 'ionic-angular';
...
this.camera.getPicture(options).then((imageUri:any) => {
imageUri = normalizeURL(imageUri);
...
https://ionicframework.com/docs/wkwebview/

@pcsantana
Copy link
Contributor

Hi!
Is this still an issue?

After a update the cordova-plugin-ionic-webview to 2.x , the image stopped to load, but no errors throws.
The path is like it:
http://localhost:8080/_file_/data/user/0/<app_id>/cache/image-loader-cache/-601073275

Any idea?
Thank you!

@pengkobe
Copy link

pengkobe commented Jan 11, 2019

after i using convertFileSrc to transform url. my logs shows Failed to load resource: net::ERR_UNKNOWN_URL_SCHEME. anyone got any ideas?

@b1ueRa1n
Copy link

after i using convertFileSrc to transform url. my logs shows Failed to load resource: net::ERR_UNKNOWN_URL_SCHEME. anyone got any ideas?

What is your local file path?

@b1ueRa1n
Copy link

Hi!
Is this still an issue?

After a update the cordova-plugin-ionic-webview to 2.x , the image stopped to load, but no errors throws.
The path is like it:
http://localhost:8080/_file_/data/user/0/<app_id>/cache/image-loader-cache/-601073275

Any idea?
Thank you!

You can try to upgrade to 3.x version, and call the "convertFileSrc" function.

@giovannipds
Copy link

giovannipds commented Jan 25, 2019

Use this and be happy. Do not downgrade as proposed by @Shtibel anymore, there's already a solution:

ionic cordova plugin add cordova-plugin-ionic-webview
npm install --save @ionic-native/ionic-webview@beta
import { WebView } from '@ionic-native/ionic-webview/ngx';

constructor(private webview: WebView) { }
...
img = this.webview.convertFileSrc('file:///Users/dan/camera-image-12345.png')

Note 1: do not forget to register Webview at your .module.
Note 2: pay attention that this will change a lot your project so you must replicate it everywhere it's needed (someone below said it had broken all the project images.

❤️

@Sampath-Lokuge
Copy link

Sampath-Lokuge commented Jan 26, 2019

@giovannipds Your solution will not work with the Ionic 3 app since it requires ionic native 5+ with Angular 7+. So need to use webview 3+ without Ionic native 5+ wrapper like so: https://stackoverflow.com/a/54269144/1077309

ihadeed added a commit that referenced this issue Feb 11, 2019
fixed wkwebview bug #183 for iOS and removed deprecated method normalizeURL
@brenden-t-r
Copy link

brenden-t-r commented Mar 7, 2019

@giovannipds

After hours of trying a million suggestions, this is what worked.

@derman10
Copy link

derman10 commented Apr 9, 2019

Can confirm.
The new ionic webview plugin is the cause for the problem.
The new plugin: cordova-plugin-ionic-webview @ 2.x seem unstable...

You can follow the issue I opened there:
ionic-team/cordova-plugin-ionic-webview#158

I downgraded back to cordova-plugin-ionic-webview@1.2.1 and all works grate.

Steps:

  1. uninstall webview
    ionic cordova plugins rm cordova-plugin-ionic-webview
  2. install old one:
    ionic cordova plugins add cordova-plugin-ionic-webview@1.2.1
  3. clean cordova
    cordova clean android

By the way angular-cropperjs is also not working with the new webview.

doing this broken all the image of the project.

@CraigAndrew
Copy link

What worked for me is simply going to the package.json file of my project root, updating the "cordova-plugin-ionic-webview" entry like so:
"cordova-plugin-ionic-webview": "2.0.0-beta.2",

Then run the 2 commands:

npm i
ionic cordova run android

@mshallaq
Copy link

mshallaq commented Feb 3, 2020

the best solution to this problem is to start using Visual Studio and then install a Live Server Extention then go live command from the footer of the page.

@azad47808
Copy link

private win: any = window;

let savePath = this.win.Ionic.WebView.convertFileSrc(path);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.