[英]IE 11 lock the file when using HTML input=file tag
I choose the file using browse in the file input in IE11
我在 IE11 中的文件输入中使用浏览选择文件
I deleted the file using shift+delete in the Explorer
我在资源管理器中使用 shift+delete 删除了文件
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 选项卡下的关联句柄子部分中,在“搜索句柄”字段中键入您的文件名。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.