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?
You can restrict the maximum allowed file size (in bytes) by using the maxFileSize property. If the selected file exceeds the maximum size, an error message will be displayed.
Open the file in any text editor and add the following code. @ini_set( 'upload_max_size' , '20M' ); @ini_set( 'post_max_size', '13M'); @ini_set( 'memory_limit', '15M' ); Save your changes, and it should increase your file upload size.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With