Skip to content

Commit 79c9c49

Browse files
author
Darryl Kuhn
committed
In some cases the file object can become invalid. For example if the user is uploading off a USB stick and removes the disk mid-upload. At that point the File object no longer has a valid reference to the file on disk. This commit aims to gracefull handle that case.
1 parent 224df70 commit 79c9c49

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
lines changed

angular-file-upload.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,10 @@ module
467467
});
468468
});
469469

470+
if ( typeof(item._file.size) != 'number' ) {
471+
throw new TypeError('The file specified is no longer valid');
472+
}
473+
470474
form.append(item.alias, item._file, item.file.name);
471475

472476
xhr.upload.onprogress = function(event) {
@@ -812,7 +816,12 @@ module
812816
* Uploads a FileItem
813817
*/
814818
FileItem.prototype.upload = function() {
815-
this.uploader.uploadItem(this);
819+
try {
820+
this.uploader.uploadItem(this);
821+
} catch (e) {
822+
this.uploader._onCompleteItem( this, '', 0, [] );
823+
this.uploader._onErrorItem( this, '', 0, [] );
824+
}
816825
};
817826
/**
818827
* Cancels uploading of FileItem

0 commit comments

Comments
 (0)