그래서 같은 문제가있었습니다. Chrome에서이를 감지하는 방법은 data.originalFiles.length > 1
을 찾고 Firefox에서는 data.files[0].size === 0
을 찾으십시오.
는 나는
singleFileUploads: false
및
limitMultiFileUploads: 1
을
minFileSize: 1
에 대한
maxNumberOfFiles: 1
을 옵션을 설정 (너무
getNumberOfFiles
를 설정!)와 함께 장난 시도
...하지만 그들 중 누구도 아주 잘 작동하는 것 같았다, 그리고 문서의 종류 퍼지하고 있었다 코드가 복잡하다.
유효성 검사 옵션 (https://github.com/blueimp/jQuery-File-Upload/wiki/Options#processqueue)이 있지만이 예제에서는 jQuery에서 더 이상 사용되지 않는 $.Deferred
메서드를 사용합니다. 이보다 더 가지고있는 경우, 기본적으로
var jqXHR = null;
$('#fileupload').fileupload({
multipart: false,
add: function(e, data) {
if (data.originalFiles.length > 1 || data.files[0].size === 0) {
fileError(null, 'zip');
} else {
jqXHR = data.submit();
}
},
error: function(jqXHR, textStatus) {
self.fileError(jqXHR, textStatus);
}
});
var fileError = function(jqXHR, textStatus) {
var statusCode = jqXHR ? jqXHR.status : 0;
// Figure out something nice to say, then close modal and clear out input box.
var friendlyError = 'Your file failed to upload.';
if (textStatus === 'abort') {
friendlyError = 'Your file upload was aborted.';
} else if (textStatus === 'error') {
friendlyError = 'There was a server error that prevented your file from being uploaded.';
} else if (textStatus === 'zip') {
friendlyError = 'This file cannot be uploaded. Please zip the file and try again.';
}
// Your custom UI code here!
};
:
그래서,이 같은 (나는 지점/조금 더 간단하게 내 사용자 정의 물건과 엑스트라를 모두 제거)을하고 결국 하나의 파일 또는 파일 크기가 0 인 경우 jqXHR
데이터를 제출하는 대신 오류 코드를 트리거하십시오. 그런 다음 fileupload
의 오류 처리를 으로 대체하십시오. DRY 때문에이 오류 처리기를 사용하십시오.
당신의 웹 응용 프로그램은 Google 크롬 55가 폴더 내부의 일부 파일 형식 (zip, doc, xls)에 대해 'file.type' (일명 ContentType) 설정을 수정하지 않는다는 것입니다. 'file.type'을 하늘의 캐릭터 라인으로 설정합니다. – dhollenbeck