Skip to content

Commit 5c18aec

Browse files
committed
Fixed: "Error after angular.copy of a File object" (#186)
1 parent c3d0fbf commit 5c18aec

File tree

6 files changed

+60
-18
lines changed

6 files changed

+60
-18
lines changed

angular-file-upload.js

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
angular-file-upload v1.0.2
2+
angular-file-upload v1.0.3
33
https://github.com/nervgh/angular-file-upload
44
*/
55
(function(angular, factory) {
@@ -720,23 +720,44 @@ module
720720

721721
/**
722722
* Creates an instance of FileLikeObject
723-
* @param {String} fakePath
723+
* @param {String|Object} fakePathOrObject
724724
* @constructor
725725
*/
726-
function FileLikeObject(fakePath) {
727-
var path = fakePath;
726+
function FileLikeObject(fakePathOrObject) {
727+
var postfix = angular.isString(fakePathOrObject) ? 'FakePath' : 'Object';
728+
var method = '_createFrom' + postfix;
729+
this[method](fakePathOrObject);
730+
}
731+
732+
/**
733+
* Creates file from fake path string
734+
* @param {String} path
735+
* @private
736+
*/
737+
FileLikeObject.prototype._createFromFakePath = function(path) {
728738
this.lastModifiedDate = null;
729739
this.size = null;
730740
this.type = 'like/' + path.slice(path.lastIndexOf('.') + 1).toLowerCase();
731741
this.name = path.slice(path.lastIndexOf('/') + path.lastIndexOf('\\') + 2);
732-
}
742+
};
743+
/**
744+
* Creates file from object
745+
* @param {File|FileLikeObject} object
746+
* @private
747+
*/
748+
FileLikeObject.prototype._createFromObject = function(object) {
749+
this.lastModifiedDate = angular.copy(object.lastModifiedDate);
750+
this.size = object.size;
751+
this.type = object.type;
752+
this.name = object.name;
753+
};
733754

734755
// ---------------------------
735756

736757
/**
737758
* Creates an instance of FileItem
738759
* @param {FileUploader} uploader
739-
* @param {File|FileLikeObject|HTMLInputElement} file
760+
* @param {File|FileLikeObject} file
740761
* @param {File|Object} options
741762
* @param {HTMLInputElement} [input]
742763
* @constructor
@@ -754,7 +775,7 @@ module
754775
method: uploader.method
755776
}, options, {
756777
uploader: uploader,
757-
file: angular.copy(file),
778+
file: new FileUploader.FileLikeObject(file),
758779
isReady: false,
759780
isUploading: false,
760781
isUploaded: false,

angular-file-upload.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)