简体   繁体   English

如何加载动态图像 tui-image-editor?

[英]How to load dynamic image tui-image-editor?

hello All,大家好,

I am using tui-image-editor npm. I want to open my editor in bootstrap model with dynamic images.我正在使用 tui-image-editor npm。我想在 bootstrap model 中用动态图像打开我的编辑器。

I am getting this errer我犯了这个错误

Access to Image at ' https://bucke_test.s3.amazonaws.com/5e4cf329adb6054a45a8203a/REN_3018.jpg ' from origin ' http://localhost:3000 ' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.从来源' https://bucke_test.s3.amazonaws.com/5e4cf329adb6054a45a8203a/REN_3018.jpg '访问图像' http://localhost:3000 '已被CORS策略阻止:No'AccessOrigin-Control ' header 出现在所请求的资源上。 Origin ' http://localhost:3000 ' is therefore not allowed access.因此不允许访问源“ http://localhost:3000 ”。 webpack://tui.ImageEditor/./src/js/invoker.js?:214 Uncaught (in promise) The executing command state is locked. webpack://tui.ImageEditor/./src/js/invoker.js?:214 Uncaught (in promise) 正在执行的命令 state 被锁定。

I already set cors permission at my s3 bucket.我已经在我的 s3 存储桶中设置了 cors 权限。

      <?xml version="1.0" encoding="UTF-8"?>
    <CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
        <CORSRule>
            <AllowedOrigin>*</AllowedOrigin>
            <AllowedMethod>GET</AllowedMethod>
            <AllowedMethod>HEAD</AllowedMethod>
            <MaxAgeSeconds>3000</MaxAgeSeconds>
            <AllowedHeader>*</AllowedHeader>
        </CORSRule>
    </CORSConfiguration> 

    <i className="fa fa-pencil cursor-pointer" aria-hidden="true" onClick={(e)=> this.openImageEditorModel("dynamicimageurl")}></i>

        openImageEditorModel = (imageURL) =>{
          document.getElementById("openImageEditor").click();
          imageEditor = new ImageEditor('#tui-image-editor', {
              includeUI: {
                  loadImage: {
                     path: imageURL,
                      name: 'Blank'
                  },
                  uiSize: {
                      width: '900px',
                      height: '500px'
                  },
                  theme: blackTheme,
                  menu: ['draw', 'text'],
                  initMenu: 'draw',
                  me[![enter image description here][1]][1]nuBarPosition: 'right'
              },
              cssMaxWidth: 600,
              cssMaxHeight: 400
          });
          imageEditor.loadImageFromURL(imageURL, 'My sample image')
        }

Maybe you can try installing this extension in the chrome browser.也许您可以尝试在 chrome 浏览器中安装此扩展程序。 I have tried it and it works on localhhost environment我已经试过了,它适用于 localhost 环境

Allow CORS: Access-Control-Allow-Origin.允许 CORS:访问控制允许来源。 https://chrome.google.com/webstore/detail/allow-cors-access-control/lhobafahddgcelffkeicbaginigeejlf?hl=en https://chrome.google.com/webstore/detail/allow-cors-access-control/lhobafahddgcelffkeicbaginigeejlf?hl=en

Unfortunately, you have jut discovered that standard browsers will not let you access image data in any meaningful way if it violates the CORS policy of the servers that served them.不幸的是,您刚刚发现标准浏览器将不允许您以任何有意义的方式访问图像数据,如果它违反了为其提供服务的服务器的 CORS 策略。 TUI Image Editor can't do anything to fix this. TUI 图像编辑器无法解决此问题。

You have two options:你有两个选择:

  1. If you control the image server (bucke_test.s3.amazonaws.com), then you should be able to set the Access-Control-Allow-Origin header to the appropriate value.如果您控制图像服务器 (bucke_test.s3.amazonaws.com),那么您应该能够将Access-Control-Allow-Origin header 设置为适当的值。 Here are the instructions you need to follow for S3 specifically. 以下是您需要专门针对 S3 遵循的说明。 For other servers/services, use a search for the header with the server name.对于其他服务器/服务,使用服务器名称搜索 header。

  2. If you don't control the image server but control your own server or server-side web application, set up an HTTP endpoint that reverse proxies the image server.如果您不控制图像服务器但控制您自己的服务器或服务器端 web 应用程序,请设置一个反向代理图像服务器的 HTTP 端点。 This way, the remote images will appear to be loaded from your origin and the image serrver's CORS policies won't affect you.这样,远程图像就会显示为从您的来源加载,并且图像服务器的 CORS 策略不会影响您。 I don't know what server you are using for your application, but all standard web servers and web application frameworks should be able to proxy requests.我不知道你的应用程序使用什么服务器,但所有标准的 web 服务器和 web 应用程序框架应该能够代理请求。 Just be careful and lock down the end point so that it doesn't get abused.请小心并锁定终点,以免滥用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM