来自本地文件系统的Electron JS图像 [英] Electron JS Images from Local File System

查看:368
本文介绍了来自本地文件系统的Electron JS图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是电子新手,正在尝试从本地文件系统加载图像以在屏幕上显示它。因此,当我这样做时,对于来自远程URL的图像来说就可以正常工作

I am new to electron and trying to load images from the local file system to display it on screen. So for images from the remote URLs are working just fine when I do

<img src='https://example.com/image.jpg' />

但是当我尝试在渲染过程中从本地文件系统加载相同的图像时,它不会工作

But when I try to load the same image from the local file system in my render process it does not work

<img src='file:///C:/tmp/image.jpg' />

未呈现。

这是我得到的错误:

> Not allowed to load local resource:
> file:///C:/tmp/nW4jY0CHsepy08J9CkF1u3CJVfi4Yvzl_screenshot.png
> dashboard:1 Not allowed to load local resource:
> file:///C:/tmp/TOyUYWnJK7VS9wWeyABhdgCNmp38FyHt_screenshot.png

是否需要进行任何配置以允许电子从本地文件系统渲染图像?或者我做错了吗?

Is there any configuration that needs to be made to allow the electron to render images from the local file system Or I am doing it entirely wrong?

推荐答案

默认情况下,电子仅允许使用<$ c $从本地源加载其html文件的渲染过程访问本地资源。 c> file:// 出于安全原因。

Electron by default allows local resources to be accessed by render processes only when their html files are loaded from local sources with the file:// protocol for security reasons.

如果要从任何 http:/加载html, / https:// 协议,即使从本地服务器(如webpack-dev-server),也无法访问本地资源。

If you are loading the html from any http:// or https:// protocol even from a local server like webpack-dev-server, access to local resources is disabled.

如果仅在开发期间从本地服务器加载html页面并在生产中切换到本地html文件,则可以

If you loading html pages from a local server only during development and switching to local html files in production, you can disable websecurity during development, taking care to enable it in production.

如果要在生产过程中从远程源加载html,最好的安全方法是将其上传到某个地方在您的服务器上并加载它。

If you are loading html from remote sources even in production, the best and secure way is to upload it somewhere on your server and load it.

这篇关于来自本地文件系统的Electron JS图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆