nolanlawson / blob-util

Cross-browser utils for working with binary Blobs
https://nolanlawson.github.io/blob-util
Apache License 2.0
503 stars 45 forks source link

Dom Exception 18 when trying to use imgSrcToBlob on an image loaded from a file:// url in WKWebView #16

Closed racekarl closed 8 years ago

racekarl commented 8 years ago

In my Cordova app I am testing WKWebView, which implements much stricter CORS checks than UIWebView.

I capture a photo from the Cordova camera plugin (which outputs a file:// uri) then load that into an Image object, if I then pass that image object to blobUtil.imgSrcToBlob I get a DOM Exception 18.

This all works correctly using UIWebView.

I guess this is because the file system does not attach CORS headers and so the blobUtil cannot call canvas.toDataURL

nolanlawson commented 8 years ago

Yeah, you can't do this unless CORS is enabled on the remote server. It's a security issue.

The solution is to enable CORS on the remote server. Sorry about that!

nolanlawson commented 8 years ago

Ooh or actually in this case, you can start a local fileserver and then use that instead of file://. Last I checked, this is how Cordova is getting around security issues with WKWebView (which is pretty broken when it comes to loading local file:// URLs).