简体   繁体   English

IE 11 在使用 HTML input=file 标签时锁定文件

[英]IE 11 lock the file when using HTML input=file tag

  1. I choose the file using browse in the file input in IE11我在 IE11 中的文件输入中使用浏览选择文件

  2. I deleted the file using shift+delete in the Explorer我在资源管理器中使用 shift+delete 删除了文件

  3. Then when I refresh the folder, the file that I deleted reappear again in Explorer.然后当我刷新文件夹时,我删除的文件再次出现在资源管理器中。

Is there anyway that I can release the file handle by at the client side javascript?无论如何,我可以在客户端javascript释放文件句柄吗? I tried that test in IE 8 but that issue didn't occurred.我在 IE 8 中尝试了该测试,但没有发生该问题。

Any kind help is appreciated.任何帮助表示赞赏。

I could release the file handler as following in IE 11.我可以在 IE 11 中如下释放文件处理程序。

    document.getElementById("fileToUpload").value=""; // input file field
    document.getElementById("uploadForm").reset(); // form that containing input file field

I was also able to release the file handler by setting the inputElement.value="" , but I wanted to add some more insight:我还可以通过设置inputElement.value=""来释放文件处理程序,但我想添加一些更多的见解:

Through trial and error I eventually found this only works if you do not reference inputElement.files in any way.通过反复试验,我最终发现这仅在您不以任何方式引用inputElement.files时才有效。 This includes even just checking for its existence.这甚至包括检查它的存在。 To keep IE11 from doing its death grip, I ended up with something like this:为了防止 IE11 陷入死循环,我最终得到了这样的结果:

// html
<form id="formID">
  <input
    id="inputID"
    name="file"
    type="file"
  />
</form>

// javascript
var formData = new FormData(document.getElementById("formID"));
someBackendService.someUploadFileMethod(formData).then(function() {
  var inputElement = document.getElementById("inputID");
  inputElement.value = "";
}

As long as the file data stays inside a FormData object, IE11 will release the lock.只要文件数据保留在FormData对象中,IE11 就会释放锁。 Unfortunately, with this setup, I was unable to find a way to support uploading multiple files or drag-and-drop.不幸的是,通过这种设置,我无法找到支持上传多个文件或拖放的方法。

A simple way to test whether the file is locked is to try renaming the directory the uploaded file came from.测试文件是否被锁定的一种简单方法是尝试重命名上传文件的来源目录。 Another way is to use the Resource Monitor that comes with Windows: under the CPU tab, in the Associated Handles subsection, type your file name in the 'Search Handles' field.另一种方法是使用 Windows 附带的资源监视器:在 CPU 选项卡下的关联句柄子部分中,在“搜索句柄”字段中键入您的文件名。

Windows 的资源监视器工具的参考图像

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 HTML文件输入 - 选择后锁定文件 - HTML file input - lock the file once selected 无法在IE 11中设置输入文件 - Not able to set input file in IE 11 在IE中设置.files文件输入标记时出错 - Error setting .files of file input tag in IE 当我使用val()函数将所选文件的名称检索到以“ C:\\ fakepath \\”开头的输入标签中时,为什么还要使用Chrome和IE? - Why using Chrome and IE when I use the val() function to retrieve the name of the selected file into an input tag it start with “C:\fakepath\”? PouchDB IE11 使用 file:// - PouchDB IE11 using file:// 如何使用JavaScript输入和输出{本地文本文件}而不是使用ActiveXObject(最新版本的Chrome或IE 11) - How to Input and Output {Local text file} instead of using ActiveXObject (latest version of Chrome or IE 11) using JavaScript input type =“ password”在IE 11上使用HTML 5显示文本 - input type=“password” shows text using HTML 5 on IE 11 使用IE 6更改本地文件时刷新本地HTML - Refresh a local HTML when a local file has changed using IE 6 IE11浏览器中的<input type =“file”>定位问题 - <input type=“file”> positioning issues in IE11 browser 表单文件输入未在IE11中正确重置 - Form file input not properly resetting in IE11
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM