Saving an image from a canvas using toDataUrl() - tainted canvas error workaround? [duplicate]

梦想与她 提交于 2019-12-11 16:59:27

问题


I'm currently building a feature where a user can upload a video, then select a thumbnail. It's based off this fiddle:

http://jsfiddle.net/e98tffu6/556/

The code to save the canvas data - starting with toDataUrl() - works under normal circumstances. Already tested it. I can get image data and post it to my action page via AJAX.

But I'm getting a classic error about the Canvas being tainted. Something like this:

Uncaught SecurityError: Failed to execute 'toDataURL' on 'HTMLCanvasElement': tainted canvases may not be exported.

That's because my video is coming from a different domain. I use a CDN.

I'm on http://example.com and loading a video from http://videos.example.com - so the code doesn't work in this specific instance.

I know that somehow using javascript, I have to set a property called crossOrigin = "Anonymous" on my source material, whether it's the video itself or the canvas. There are a million variations of this question on SO. I've looked at them all, and I still can't figure out what I'm doing.

Can anybody put together an example where toDataUrl() works in this situation?

Thanks in advance.

来源:https://stackoverflow.com/questions/45250974/saving-an-image-from-a-canvas-using-todataurl-tainted-canvas-error-workaroun

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!