如果知道位置,是否可以在本地文件上使用Javascript的FileReader? [英] Can I use Javascript's FileReader on a local file if I know the location?

查看:69
本文介绍了如果知道位置,是否可以在本地文件上使用Javascript的FileReader?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将JavaScript与FileReader和readAsDataURL一起使用,因此可以将图像转换为base64代码,然后在以后存储和显示base64图像代码.我有一个按钮,当我选择一个文件时,该按钮可以正常工作,但是我的问题是:如何仅使用本地文件的url(类似C:\ folder \ image.gif之类的文件)(不使用文件输入按钮) ),然后从该本地图像文件url创建一个图像对象,以便与FileReader的readAsDataURL函数一起使用?如果FileReader无法做到这一点,那么还有另一种方法可以在脚本中自动将本地文件转换为base64代码吗?

I am using JavaScript with FileReader and readAsDataURL so I can convert images to base64 code and then store and display the base64 image code at a later time. I have a button that works fine when I select a file with it, but my question is: How can I use only a url to a local file (something like C:\folder\image.gif) (without using the file input button) and create an image object from that local image file url to use with the FileReader readAsDataURL functions? If this is not possible with FileReader, is there another way to automatically convert a local file to base64 code within the script?

推荐答案

您不能.允许网站打开任意本地文件将是一个严重的,严重的安全问题.在用户不知情的情况下,将无法阻止诸如获取密码文件或其他敏感信息之类的事情.因此,在文件输入方面也有严格的限制,以便清楚地传达意图.

You can't. Allowing a web site to open arbitrary local files would be a serious, serious security concern. There would be nothing to prevent things like grabbing password files or other sensitive information without the user knowing. There have also been strict restrictions on the file input for that reason and to clearly communicate the intent.

这篇关于如果知道位置,是否可以在本地文件上使用Javascript的FileReader?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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