How can I limit the size of attachment (file upload) in AngularJS?
angular-ui, angularjs, angularjs-directive, angularjs-ng-repeat, angularjs-scope
Solution
While this question is somewhat old, I still think it's worthwhile to provide the best possible answer for those seeking it. The answer above relies on jQuery for the superficial aspects, but let's use a style fitting for Angular development.
Here I reference the actual library author's own recommendation when asked the same question, altering it for the size asked in the question above:
uploader = new FileUploader();
//...
uploader.filters.push({
'name': 'enforceMaxFileSize',
'fn': function (item) {
return item.size <= 10485760; // 10 MiB to bytes
}
});
EXAMPLE UPDATED ABOVE: to reflect changes to the `angular-file-upload` API.
Note that this relies on the file's `size` attribute (Blob size in bytes), which is supported only by modern browsers (namely IE10 and up).
Problem
I want the best way to upload files with loading image in AngularJS. At the same time i want to limit the size to 10MB. Please give the best way to achieve this?