简体   繁体   English

在结构 Image.fromURL function 中传递标头

[英]Pass headers in fabric Image.fromURL function

I am using fabric.js Image.fromURL function to load the image to canvas.我正在使用 fabric.js Image.fromURL function 将图像加载到 canvas。 For now, the images are loading successfully without any issues.目前,图像已成功加载,没有任何问题。 But now I have a requirement to pass headers for authentication purposes is there a way that I could pass headers into the "Image.fromURL" function or any other way I could incorporate my headers to it.但是现在我需要传递标头以进行身份验证,有没有一种方法可以将标头传递到“Image.fromURL”function 或任何其他可以将我的标头合并到其中的方式。

Image.fromUrl doesn't send a request. Image.fromUrl 不发送请求。 As you can see here in source code this function uses fabric.util.loadImage , that as you can see here creates an image and set src attribute.正如您在源代码中看到的, function 使用fabric.util.loadImage ,正如您在此处看到的那样创建图像并设置src属性。 Thus the browser makes the request for getting the image itself.因此,浏览器发出获取图像本身的请求。 And you cannot send your own headers using Image.FromURL function而且您不能使用 Image.FromURL function 发送自己的标头

I think you can get your images something like this (it's just idea):我认为你可以得到这样的图像(这只是想法):

const image = new Image();
image.onload = () => {
  const fabricImage = new fabric.Image(image);
  canvas.add(fabricImage);
}

fetch("https://your-url", {headers: {}}).then((res)=>{
  image.src = res;
})

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

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