cordova-plugin-ionic-webview
cordova-plugin-ionic-webview copied to clipboard
Canvas and Cors
Im trying to load local images into canvas (openlayer) and prevent my canvas from getting tainted in the process.
I cannot load "file:///..." urls because it is not allowed.
And I cannot request it from localhost (this.webview.convertFileSrc) hence CORS.
How can I solve the CORS issue that is requesting files locally?
can you provide more information about the issue? in which platforms do you get the problem? how do you run the app? can you provide a sample app?
same issue here with canvas and canvas need crossOrigin="anonymous" to work even cors (*) is enable at s3 bucket when you place crossOrigin="anonymous" in img element you will get cors error
Edit: creating small application to reproduce
Edit1: Don't know whats going on its working fine in sample application but not in actual application i copied same component over there.
same from server team they have created cloudfront and map to s3 hosted image. now i am getting proper response header from access origin *
https://stackoverflow.com/questions/57440211/how-to-load-an-image-into-a-canvas-without-cors-issues-for-ionic-ios-hybrid-app
use cordova native http, or cordova-plugin-wkwebview-file-xhr.
@xiazhe Still an issue, because I need to provide "path" or "url" to an image.
Anybody found a solution? Have the same issue here
I was trying to do canvas.toDataURL to images with "file:///" schemes on iOS in Cordova, and getting various errors, including: "Origin null is not allowed by Access-Control-Allow-Origin."
The solution that worked for me involved two steps:
- Add to the
<platform name="ios">section of config.xml:
<preference name="scheme" value="app" />
<preference name="hostname" value="localhost" />
as documented here: https://cordova.apache.org/announcements/2020/06/01/cordova-ios-release-6.0.0.html
- Update the filename returned in the Success callback from navigator.camera.getPicture(), from the "file:///" scheme to your new "app://" scheme using:
imageFileName = window.WkWebView.convertFilePath( imageFileName )
as (kind of) documented here: https://github.com/apache/cordova-plugin-camera/issues/622#issuecomment-659357799
@Michael-Stanford thank you. The project was probably created before the release of 6.0, that is maybe the reason for lack of complaints. Changing config.xml would probably require generating new project, and I assume it adds/changes something in info.plist file (iOS). Would be nice if somebody knew the right config for the "bugfix". (As with linked issue, it appears only in live reload mode)
Is there an update?