如何从Blazor Wasm的第三方网站检索图像流?

发布于 2025-01-30 16:29:13 字数 721 浏览 1 评论 0原文

我们正在尝试在Blazor Wasm构建图像编辑器。 源图像是第三方站点,因此,当我们使用httpclient检索数据时,我们会遇到CORS错误。

因此,我们设置了一个“代理”(不完全是代理),而是一个将检索图像然后流式传输的ASP.NET API,以避免CORS问题。但是现在,由于这是AWS lambda,所以我们遇到了AWS lambda有效载荷限制。

然后,我们尝试了httprequestmessage.setBrowserRequestMode(browserrequestmode.nocors),然后跑入: https://github.com/dotnet/aspnetcore/issues/24080

我们似乎正在用完选项。

我想做的下一个尝试是允许图像自然流到第三方托管站点的< img>。这似乎是有效的,因为浏览器不会在第三方网站检索数据上丢下CORS错误。

无论如何,Blazor Wasm是否有从< img>中“窃取”图像数据并将其放入字节数组或流中,以便我们可以使用图像数据?

关于如何将大图像文件加载到流或字节数组给定上述约束的任何其他想法?

我还考虑过块,但这似乎很麻烦。

We are trying to build an image editor in Blazor WASM.
The source image is a 3rd party site, so when we use HttpClient to retrieve the data, we are hit with a CORS error.

So, we setup a "proxy" (not exactly a proxy), but an ASP.NET API that would retrieve the image and then stream it, to avoid the CORS problem. But now, because this is AWS Lambda, we are running into the AWS Lambda payload limit.

We then tried HttpRequestMessage.SetBrowserRequestMode(BrowserRequestMode.NoCors) and ran into this: https://github.com/dotnet/aspnetcore/issues/24080

We are seemingly running out options.

My next attempt I would like to do is allow the image to flow naturally to <img> from the 3rd party hosting site. This seems to work as the browser does NOT throw a CORS error on the retrieving the data from a 3rd party site.

Is there anyway in Blazor WASM to "steal" the image data from the <img> and put it into a byte array or stream so that we have the image data to work with?

Any other ideas on how to load a large image file into a stream or byte array given the above constraints?

I've also considered chunking it, but that seems like a big hassle.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文