- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在 Safari 11 中重现该错误的步骤:
实际结果:文件未上传。
为了更好地理解,请观看 Safari 11 的视频:https://drive.google.com/open?id=16tU8iBn0U9bUs7u5pM4ZBXmxpfJIv8WV
尝试上传相同的文件,但使用 Safari 10。
实际结果:一切正常,文件上传没有任何问题。
为了更好地理解,请观看 Safari 10 的视频:https://drive.google.com/open?id=1IO--Y1RjETAYAucaNyqhM6HZcQdNKDkI
更新2018年5月28日通过 crossbrowsertesting.com 进行了几个小时的调试(因为我没有 safari),我找到了临时解决方案:就这条线https://github.com/blueimp/jQuery-File-Upload/blob/master/js/jquery.fileupload.js#L1182需要更换
entries = fileInput.prop('webkitEntries') || fileInput.prop('entries')
到
entries = []
一切都应该有效。
我猜这是因为苹果添加了 safari 实验性功能 - FileSystemEntry。有关此功能的更多信息 https://developer.mozilla.org/en-US/docs/Web/API/FileSystemEntry .
如果 entries
变量为空 jquery.fileupload.js 将使用用于获取上传文件的久经考验的 files
属性。查看代码https://github.com/blueimp/jQuery-File-Upload/blob/master/js/jquery.fileupload.js#L1189了解更多详情
我还向 Safari 和 Sebastian Tschan(该库的作者)报告了一个错误
最佳答案
我现在也发现了同样的问题。我已经检测到代码片段:jquery.fileupload.js
_handleFileTreeEntry: function (entry, path) {
var that = this,
dfd = $.Deferred(),
errorHandler = function (e) {
if (e && !e.entry) {
e.entry = entry;
}
// Since $.when returns immediately if one
// Deferred is rejected, we use resolve instead.
// This allows valid files and invalid items
// to be returned together in one set:
dfd.resolve([e]);
},
successHandler = function (entries) {
that._handleFileTreeEntries(
entries,
path + entry.name + '/'
).done(function (files) {
dfd.resolve(files);
}).fail(errorHandler);
},
readEntries = function () {
dirReader.readEntries(function (results) {
if (!results.length) {
successHandler(entries);
} else {
entries = entries.concat(results);
readEntries();
}
}, errorHandler);
},
dirReader, entries = [];
path = path || '';
if (entry.isFile) {
if (entry._file) {
// Workaround for Chrome bug #149735
entry._file.relativePath = path;
dfd.resolve(entry._file);
} else {
entry.file(function (file) { // <=== here
file.relativePath = path;
dfd.resolve(file);
}, errorHandler);
}
} else if (entry.isDirectory) {
dirReader = entry.createReader();
readEntries();
} else {
// Return an empy list for file system items
// other than files or directories:
dfd.resolve([]);
}
return dfd.promise();
}
在此函数中,当代码遇到条件时
entry.file(function (file) {
file.relativePath = path;
dfd.resolve(file);
}, errorHandler);
Safari 正在返回文件函数回调的 errorHandler。函数 api 引用在这里:https://developer.mozilla.org/en-US/docs/Web/API/FileSystemFileEntry/file .
这肯定是Safari 11的bug。很快我就会向苹果报告这个错误。在 jQuery.fileupload.js 中,我想更好的修复方法是使用 Safari 11 检测 UserAgent。但我认为 Apple 应该解决这个问题。
关于jQuery文件上传: cannot upload file in Safari 11,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49918319/
我有以下正则表达式 /[a-zA-Z0-9_-]/ 当字符串只包含从 a 到z 大小写、数字、_ 和 -。 我的代码有什么问题? 能否请您向我提供一个简短的解释和有关如何修复它的代码示例? //var
我是一名优秀的程序员,十分优秀!