Load cross domain image in texture

谁都会走 提交于 2019-12-24 00:39:08

问题


How to load cross domain image in textureloader and im getting "Failed to execute 'texImage2D' on 'WebGLRenderingContext': The cross-origin..." error

var loader = new THREE.TextureLoader();
loader.load('http://myurl.com/img/box.png', onTextureLoaded);

回答1:


First option

Add a CORS header to the asset, permitting cross-domain requests:

Access-Control-Allow-Origin: *

Second option

You can create a server side proxy, and then load the asset like this

loader.load('myproxy?url=http://myurl.com/img/box.png', onTextureLoaded);

However you need to be careful, as proxies can use up a lot of bandwidth and you need to be very thorough when setting it up so you don't accidentally open your server to some code injection attacks.



来源:https://stackoverflow.com/questions/36883592/load-cross-domain-image-in-texture

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