Internet Explorer 缓存文件上传?

Internet Explorer Caching File Uploads?

我有一个非常基本的页面,其中包含一个 <input type="file"> 元素。当我提交带有 selected 文件的表单时,服务器响应一个在 Excel("new window")中打开的电子表格。此行为的含义是初始屏幕和输入元素在 IE 中仍然可见。如果我更改 selected 文件磁盘上的数据并重新提交表单,Internet Explorer 会再次上传旧内容;我的最新更改未出现在发送到服务器的内容中。如果我 select 文件再次通过输入的浏览...按钮,新文件内容将按预期上传。 Firefox 始终从磁盘发送文件内容,这是 expected/desired 行为。似乎 Internet Explorer 正在对上传的文件内容进行某种缓存。

有什么方法可以禁用此功能 "feature" 并让 IE 在每次提交表单时从磁盘中提取数据?

是否有任何关于此行为的文档?这是我第一次遇到它,我的搜索基本上是空的。

我自己没有尝试过,但您可能想尝试对表单操作使用虚拟参数并在每次提交操作之前更改其值。例如,如果您有 <form action="foo.php">,请将其更改为 <form action="foo.php?dummy=0">,然后使用 javascript 将操作部分更改为例如action="foo.php?dummy=1" 等等,就在每次提交之前。

您是否尝试过为您的 input 标签使用 autocomplete 属性?

例如

<input type="text" autocomplete="off" />

应该强制 值永远不会被重复使用 W3C docs 中所述:

autocomplete = on/ off/ default

  • on - The on state indicates that the value is not particularly sensitive and the user can expect to be able to rely on his user agent to remember values he has entered for that control.
  • off - The off state indicates either that the control's input data is particularly sensitive (for example the activation code for a nuclear weapon); or that it is a value that will never be reused (for example a one-time-key for a bank login) and the user will therefore have to explicitly enter the data each time, instead of being able to rely on the UA to prefill the value for him; or that the document provides its own autocomplete mechanism and does not want the user agent to provide autocompletion values.

你可以用live demos posted on MS-Connect来验证这个猜想。

[...]该错误始于 IE10,当时实现了 FileList 和 Blob。
input.files 是一个包含 file/blob 项的 html5 文件列表。
为了填充它,IE 将每个文件选择器选择变成 blob。他们有一个 "snapshot state"(W3C 术语)。
它们会保持同步,以防所选文件在提交前更新。
错误是,IE 无法检测文件是否被删除、重命名或替换。
在这种情况下,文件选择器快照会过时。

这是在文件选择器中选择文件,然后 重命名编辑,然后再提交文件选择器选择时发生的情况。尽管新文件(具有原始文件名)已被替换,原始文件(现在具有 different name 和修改后的文本)被发送在表格中。这怎么可能?就好像它是通过 ntfs ObjectID 跟踪的,它与 Distributed Link Tracking 一起使用。请注意此屏幕截图中的文件 name 与文件 content.

不一致

所以,这根本不是 "caching" 的事情。这是一个跟踪错误。

我在 IE 10,11 中遇到了同样的问题。我可以使用以下代码修复它

var file = $('input[type="file"]');
file.removeAttr('value');
var cloneFile = file.clone();
file.parent().get(0).replaceChild(cloneFile.get(0), file.get(0));

如果您为文件获取多个对象,则在选择器之后使用 eq(-2),例如

$('input[type="file"]').eq(-2);

如有任何问题,请评论我。