Can I use Javascript's FileReader on a local file if I know the location?

半腔热情 提交于 2019-12-25 05:18:08

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/12764583/can-i-use-javascripts-filereader-on-a-local-file-if-i-know-the-location

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!