绕过浏览文件/上传文件对话框 [英] Bypassing the browse file / upload file dialog

查看:128
本文介绍了绕过浏览文件/上传文件对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个供内部使用的Chrome扩展程序,用户只需一步就可以上传文件。这是总是同一个文件,我想跳过浏览对话框,并直接为输入字段分配正确的值。

该文件与插件代码是分开的。

这是可能的Javascript或开发Chrome,Firefox扩展?



我试过了:

  input.val(file: //C:/random.txt)

然后提交周围的表单。但是这没有用。

解决方案

Firefox:你想要的可能根据这个答案,但我没有Chrome浏览器:



NPAPI插件,这是绝对不可能的。您的浏览器无法访问文件系统,除非用户通过文件对话框明确要求这样做。如果Web上的任何页面都能够以编程方式设置文件路径,然后在用户单击表单按钮时获取文件,则会引发大量的安全问题。

所以,一个正常的网页显然不能这样做。如果Chrome扩展程序可以做到这一点(即读取文件系统中的任何文件),那么它至少需要一个特殊的权限。 权限列表不包含文件系统访问权限,因此不存在问题。

正如我刚才提到的,唯一的选择是开发一个NPAPI插件来为你读取文件,这就像建一个医院对待一个疙瘩。 NPAPI有一个非常陡峭的开发学习曲线,它引入了重要的安全问题(因为你的扩展现在可以作为本地用户,安全妥协的成本要高得多)。

如果您愿意将文件放在浏览器的虚拟HTML5文件系统上,一个>,那么你可以做到这一点。如果没有你的需求的具体知识,我不能说这是否适合你。


I am building a Chrome extension for internal use, and at one step, the user can upload a file. This is always the same file, and I would like to skip the browse dialog and directly assign the proper value to the input field.

The file is separate from the plugin code.

Is this possible with Javascript, or developing Chrome, Firefox extensions?

I have tried:

input.val("file://C:/random.txt")

and then submit the surrounding form. But that did not work.

解决方案

Firefox:

What you want seems to be possible according to this answer, but I haven't investigated it closely.

Chrome:

Outside of an NPAPI plugin, this is definitely not possible. Your browser cannot access the filesystem except when the user explicitly asks it to do so via a file dialog. If any page on the Web were able to programmatically set a filepath and then fetch the file when the user clicks a form button, that would raise massive security concerns.

So, a normal webpage certainly can't do it, obviously. If a Chrome extension could do it (i.e. read any file in the filesystem) then it would at the bare minimum require a special permission. The list of permissions does not include filesystem access, so that's out of the question.

The only option, as I mentioned in the beginning, would be to develop an NPAPI plugin to the read the file for you, which would be like building a hospital to treat a pimple. NPAPI has a pretty steep development learning curve, and it introduces significant security concerns (since your extension can now act the local user, the cost of a security compromise is much higher).

If you're willing to place the file on the browser's virtual HTML5 filesystem, then you could do that. Without specific knowledge of your needs, I can't say if that will be appropriate for you.

这篇关于绕过浏览文件/上传文件对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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