Lightweight Angular directive to upload files with optional FileAPI shim for cross browser support
Lightweight Angular directive to upload files with optional FileAPI shim for cross browser support
Lightweight Angular directive to upload files.
See the DEMO page. Reference docs here
Migration notes: version 3.0.x version 3.1.x version 3.2.x version 4.x.x version 5.x.x version 6.x.x version 6.2.x version 7.0.x version 7.2.x version 8.0.x version 9.0.x version 10.0.x version 11.0.x version 12.0.x version 12.1.x version 12.2.x
Ask questions on StackOverflow under the ng-file-upload tag.
For bug report or feature request please search through existing issues first then open a new one here. For faster response provide steps to reproduce/versions with a jsfiddle link. If you need support for your company contact me.
If you like this plugin give it a thumbs up at ngmodules or get me a cup of tea . Contributions are welcomed.
Table of Content:
ng-required with pluggable custom sync or async validations.Upload.$http()bower install ng-file-upload-shim --save(for non html5 suppport)bower install ng-file-upload --savePM> Install-Package angular-file-upload (thanks to Georgios Diamantopoulos)npm install ng-file-upload<script src="angular(.min).js"></script>
<script src="ng-file-upload-shim(.min).js"></script>
<script src="ng-file-upload(.min).js"></script><script src="angular.min.js"></script>
<script src="ng-file-upload-shim.min.js"></script>
<script src="ng-file-upload.min.js"></script>
Upload on form submit or button click
<form ng-app="fileUpload" ng-controller="MyCtrl" name="form">
Single Image with validations
Multiple files
Drop files:
<button type="submit" ng-click="submit()">submit</button>
</form>
Upload right away after file selection:
Drop File:
Image thumbnail:
Audio preview: <audio controls ngf-src="file"></audio>
Video preview: <video controls ngf-src="file"></video>Javascript code:
…At least one of the ngf-select or ngf-drop are mandatory for the plugin to link to the element.
ngf-select only attributes are marked with * and ngf-drop only attributes are marked with +.
<a href="file | ngfDataUrl">image</a>
*ngf-background="file"
ngf-resize="{width: 20, height: 20, quality: 0.9}"
ngf-no-object-url="true or false"
>
<div|span|...
*ngf-thumbnail="file"
ngf-size="{width: 20, height: 20, quality: 0.9}" the image will be resized to this size
ngf-as-background="boolean"
>…ng-model The model value will be a single file instead of an array if all of the followings are true:
ngf-multiple is not set or is resolved to false.multiple attribute is not set on the elementngf-keep is not set or is resolved to false.validation
When any of the validation directives specified the form validation will take place and
you can access the value of the validation using myForm.myFileInputName.$error.<validate error name>
for example form.file.$error.pattern.
If multiple file selection is allowed you can specify ngf-model-invalid="invalidFiles" to assing the invalid files to
a model and find the error of each individual file with file.$error and description of it with file.$errorParam.
You can use angular ngf-model-options to allow invalid files to be set to the ng-model ngf-model-options="{allowInvalid: true}".
Upload multiple files: Only for HTML5 FormData browsers (not IE8-9) you have an array of files or more than one file in your data to
send them all in one request . Non-html5 browsers due to flash limitation will upload each file one by one in a separate request.
You should iterate over the files and send them one by one for a cross browser solution.
drag and drop styling: For file drag and drop, ngf-drag-over-class could be used to style the drop zone.
It can be a function that returns a class name based on the $event. Default is "dragover" string.
Only in chrome It could be a json object {accept: 'a', 'reject': 'r', pattern: 'image/*', delay: 10} that specify the
class name for the accepted or rejected drag overs. The pattern specified or ngf-pattern will be used to validate the file's mime-type
since that is the only property of the file that is reported by the browser on drag. So you cannot validate
the file name/extension, size or other validations on drag. There is also some limitation on some file types which are not reported by Chrome.
delay default is 100, and is used to fix css3 transition issues from dragging over/out/over #277.
Upload.setDefaults():
If you have many file selects or drops you can set the default values for the directives by calling Upload.setDefaults(options). options would be a json object with directive names in camelcase and their default values.
Resumable Uploads: The plugin supports resumable uploads for large files. On your server you need to keep track of what files are being uploaded and how much of the file is uploaded.
url upload endpoint need to reassemble the file chunks by appending uploading content to the end of the file or correct chunk position if it already exists.resumeSizeUrl server endpoint to return uploaded file size so far on the server to be able to resume the upload from
where it is ended. It should return zero if the file has not been uploaded yet. size integer property. If you return other formats from the endpoint you can specify
resumeSizeResponseReader function to return the size value from the response. Alternatively instead of resumeSizeUrl you can use
resumeSize function which returns a promise that resolves to the size of the uploaded file so far.
Make sure when the file is fully uploaded without any error/abort this endpoint returns zero for the file size
if you want to let the user to upload the same file again. Or optionally you could have a restart endpoint to
set that back to zero to allow re-uploading the same file.resumeChunkSize optionally you can specify this to upload the file in chunks to the server. This will allow uploading to GAE or other servers that have
file size limitation and trying to upload the whole request before passing it for internal processing._chunkSize, _currentChunkSize, _chunkNumber (zero starting), and _totalSize to help the server to write the uploaded chunk to
the correct position.
Uploading in chunks could slow down the overall upload time specially if the chunk size is too small.
When you provide resumeChunkSize option one of the resumeSizeUrl or resumeSize is mandatory to know how much of the file is uploaded so far.For browsers not supporting HTML5 FormData (IE8, IE9, ...) FileAPI module is used.
Note: You need Flash installed on your browser since FileAPI uses Flash to upload files.
These two files FileAPI.min.js, FileAPI.flash.swf will be loade
A
ختمة
Itinerario
Test
Abinash file
support Angular2 or later
Unable to send/receive custom metadata with S3 Upload
ngf-fix-orientation creates invalid image file due to misinterpretation of exif metadata
Click on button with ngf-select no longer working in latest Chrome
Missing width and height in the upload return object