Typeerror: Cannot Read Property '$$phase' of Null Ng-file-upload
ng-file-upload
Lightweight Athwart directive to upload files.
Run into the DEMO page. Reference docs here
Migration notes: version 3.0.x version 3.ane.10 version 3.2.x version 4.x.x version five.ten.x version half-dozen.x.x version half-dozen.2.x version seven.0.x version 7.2.x version eight.0.ten version 9.0.10 version ten.0.10 version xi.0.ten version 12.0.ten version 12.i.x version 12.2.x
Enquire 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 y'all need support for your company contact me.
If you similar this plugin requite information technology a thumbs upwardly at ngmodules or get me a cup of tea
. Contributions are welcomed.
Table of Content:
- Features
- Install (Manual, Bower, NuGet, NPM)
- Usage
- Quondam Browsers
- Server Side
- Samples (Coffee, Spring, Node.js, Rails, PHP, .Net)
- CORS
- Amazon S3 Upload
Features
- file upload progress, cancel/abort
- file drag and drop (html5 only)
- image paste from clipboard and drag and drop from browser pages (html5 but).
- image resize and centre crop (native) and user controlled crop through ngImgCrop. Meet crop sample (html5 only)
- orientation prepare for jpeg prototype files with exif orientation data
- resumable uploads: suspension/resume upload (html5 only)
- native validation support for file type/size, paradigm width/pinnacle/aspect ratio, video/sound duration, and
ng-requiredwith pluggable custom sync or async validations. - show thumbnail or preview of selected images/sound/videos
- supports CORS and directly upload of file'south binary data using
Upload.$http() - enough of sample server side code, bachelor on nuget
- on need flash FileAPI shim loading no extra load for html5 browsers.
- HTML5 FileReader.readAsDataURL shim for IE8-nine
- available on npm, bower, meteor, nuget
Install
- Manual: download latest from here
- Bower:
-
bower install ng-file-upload-shim --save(for non html5 suppport) -
bower install ng-file-upload --save
-
- NuGet:
PM> Install-Bundle angular-file-upload(thanks to Georgios Diamantopoulos) - NPM:
npm install ng-file-upload
Usage
Samples:
- Upload with form submit and validations: http://jsfiddle.net/danialfarid/maqbzv15/1118/
- Upload multiple files one by one on file select: http://jsfiddle.net/danialfarid/2vq88rfs/136/
- Upload multiple files in 1 request on file select (html5 only): http://jsfiddle.internet/danialfarid/huhjo9jm/five/
- Upload single file on file select: http://jsfiddle.net/danialfarid/0mz6ff9o/135/
- Driblet and upload with $watch: http://jsfiddle.net/danialfarid/s8kc7wg0/400/
- Paradigm Crop and Upload http://jsfiddle.net/danialfarid/xxo3sk41/590/
Upload on form submit or button click
Unmarried Image with validations
Select
Multiple files
Select
Drop files: Drop
submit
Upload right abroad after file pick:
Upload on file select
Upload on file select
Drop File:
Drop Images or PDFs files here
File Drag/Drop is not supported for this browser
Image thumbnail:
Audio preview:
Video preview:
Javascript code:
var app = angular ;
app
;
Total reference
File select and drop
At to the lowest degree 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-driblet merely attributes are marked with +.
Upload/Drop
File Drag/drib is not supported
// filter to convert the file to base64 data url.
image
File preview
Upload service:
var upload = Upload
upload
;
upload ;
upload ;
upload
;
upload ;
Upload
Upload
Upload defaults blobUrlsMaxMemory = 268435456
Upload defaults blobUrlsMaxQueueSize = 200
Upload ;
Upload ;
Upload ;
Upload ;
Upload ;
Upload
Upload
Upload
Upload
Upload
var blob = upload ;
Upload boolean
Upload ;
Upload ;
Upload
ng-model The model value will be a single file instead of an assortment if all of the followings are true:
-
ngf-multipleis not ready or is resolved to simulated. -
multipleattribute is not set on the element -
ngf-keepis non set or is resolved to simulated.
validation When any of the validation directives specified the form validation will take place and you lot can access the value of the validation using myForm.myFileInputName.$error.<validate error name> for example form.file.$error.pattern. If multiple file choice is allowed y'all 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. Y'all can utilise angular ngf-model-options to allow invalid files to exist set to the ng-model ngf-model-options="{allowInvalid: truthful}".
Upload multiple files: Just for HTML5 FormData browsers (not IE8-9) you have an array of files or more than 1 file in your data to send them all in one request . Non-html5 browsers due to wink limitation volition upload each file 1 by one in a divide request. You should iterate over the files and send them ane past one for a cross browser solution.
drag and drop styling: For file drag and drop, ngf-elevate-over-class could exist used to fashion the drop zone. It can be a role that returns a class name based on the $outcome. Default is "dragover" string. Simply in chrome It could be a json object {take: 'a', 'reject': 'r', blueprint: 'image/*', delay: 10} that specify the class name for the accepted or rejected drag overs. The pattern specified or ngf-design will be used to validate the file'southward mime-blazon since that is the merely property of the file that is reported by the browser on drag. And so you lot cannot validate the file name/extension, size or other validations on drag. In that location is also some limitation on some file types which are not reported past Chrome. delay default is 100, and is used to ready css3 transition problems from dragging over/out/over #277.
Upload.setDefaults(): If you have many file selects or drops you can set up 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 demand to go along track of what files are being uploaded and how much of the file is uploaded.
-
urlupload endpoint need to reassemble the file chunks by appending uploading content to the stop of the file or correct clamper position if it already exists. -
resumeSizeUrlserver endpoint to return uploaded file size then far on the server to be able to resume the upload from where it is ended. Information technology should render zilch if the file has not been uploaded yet.
A Become request will be made to that url for each upload to determine if office of the file is already uploaded or not. You lot need a unique way of identifying the file on the server so you lot can pass the file name or generated id for the file equally a request parameter.
By default it volition assume that the response content is an integer or a json object withsizeinteger property. If yous render other formats from the endpoint you tin can specifyresumeSizeResponseReaderfunction to return the size value from the response. Alternatively instead ofresumeSizeUrlyou can utiliseresumeSizerole 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 lot desire to permit the user to upload the same file again. Or optionally you could take a restart endpoint to set that dorsum to zero to let re-uploading the aforementioned file. -
resumeChunkSizeoptionally yous tin specify this to upload the file in chunks to the server. This will permit uploading to GAE or other servers that take file size limitation and trying to upload the whole request earlier passing it for internal processing.
If this option is set up the requests will have the following extra fields:_chunkSize,_currentChunkSize,_chunkNumber(zero starting), and_totalSizeto help the server to write the uploaded chunk to the correct position. Uploading in chunks could tedious down the overall upload time peculiarly if the chunk size is likewise small. When you provideresumeChunkSizeoption one of theresumeSizeUrlorresumeSizeis mandatory to know how much of the file is uploaded then far.
Old browsers
For browsers not supporting HTML5 FormData (IE8, IE9, ...) FileAPI module is used. Note: Yous need Flash installed on your browser since FileAPI uses Flash to upload files.
These two files FileAPI.min.js, FileAPI.flash.swf will be loaded by the module on need (no demand to exist included in the html) if the browser does non supports HTML5 FormData to avoid actress load for HTML5 browsers. Yous can place these two files abreast angular-file-upload-shim(.min).js on your server to be loaded automatically from the same path or you tin can specify the path to those files if they are in a different path using the following script:
...
Quondam browsers known bug:
- Considering of a Flash limitation/bug if the server doesn't send any response body the status code of the response volition be ever
204 'No Content'. So if you have access to your server upload lawmaking at to the lowest degree return a character in the response for the condition code to work properly. - Custom headers will not work due to a Wink limitation #111 #224 #129
- Due to Flash problems #92 Server HTTP fault code 400 will exist returned as 200 to the client. So avoid returning 400 on your server side for upload response otherwise it volition be treated as a success response on the client side.
- In instance of an mistake response (http code >= 400) the custom error message returned from the server may not be bachelor. For some error codes flash merely provide a generic error message and ignores the response text. #310
- Older browsers won't allow
PUTrequests. #261
Server Side
- Java You can find the sample server lawmaking in Java/GAE here
- Leap MVC Wiki Sample provided past zouroto
- Node.js Wiki Sample provided by chovy. Another wiki using Express 4.0 and the Multiparty provided past Jonathan White
- Rails
- Wiki Sample provided by guptapriyank.
- Blog mail service provided by Coshx Labs.
- Rail progress result: If your server is Rails and Apache you lot may need to change server configurations for the server to back up upload progress. See #207
- PHP Wiki Sample and related issue only i file in $_FILES when uploading multiple files
- .Net
- Demo showing how to utilize ng-file-upload with Asp.Cyberspace Spider web Api.
- Sample customer and server code demo/C# provided by AtomStar
CORS
To support CORS upload your server needs to allow cross domain requests. Yous can achieve that by having a filter or interceptor on your upload file server to add CORS headers to the response similar to this: (sample coffee code)
httpResp . ;
httpResp . ;
httpResp . ) ;
For not-HTML5 IE8-9 browsers y'all would also need a crossdomain.xml file at the root of your server to allow CORS for wink: (sample xml)
Amazon AWS S3 Upload
For Amazon authentication version 4 meet this comment
The demo folio has an option to upload to S3. Here is a sample config options:
Upload
;
This article explains more virtually these fields and provides instructions on how to generate the policy and signature using a server side tool. These 2 values are generated from the json policy certificate which looks like this:
" expiration " : " 2020-01-01T00:00:00Z "
" weather condition " :
" bucket " : " athwart-file-upload "
" starts-with " " $key " " "
" acl " : " individual "
" starts-with " " $Content-Type " " "
" starts-with " " $filename " " "
" content-length-range " 0 524288000
The demo page provide a helper tool to generate the policy and signature from you from the json policy document. Note: Delight utilize https protocol to admission demo folio if you are using this tool to generate signature and policy to protect your aws secret cardinal which should never be shared.
Brand sure that you provide upload and CORS mail to your bucket at AWS -> S3 -> bucket proper name -> Properties -> Edit bucket policy and Edit CORS Configuration. Samples of these two files:
" Version " : " 2012-10-17 "
" Statement " :
" Sid " : " UploadFile "
" Consequence " : " Let "
" Principal " :
" AWS " : " arn:aws:iam::xxxx:user/xxx "
" Action " :
" s3:GetObject "
" s3:PutObject "
" Resource " : " arn:aws:s3:::angular-file-upload/* "
" Sid " : " crossdomainAccess "
" Event " : " Allow "
" Principal " : " * "
" Action " : " s3:GetObject "
" Resource " : " arn:aws:s3:::angular-file-upload/crossdomain.xml "
http://angular-file-upload.appspot.com
POST
GET
HEAD
3000
*
For IE8-9 flash polyfill you need to accept a crossdomain.xml file at the root of y'all S3 bucket. Make sure the content-blazon of crossdomain.xml is text/xml and you provide read access to this file in your bucket policy.
You can also have a look at https://github.com/nukulb/s3-angular-file-upload for another instance with this set up.
Source: https://www.npmjs.com/package/ng-file-upload
0 Response to "Typeerror: Cannot Read Property '$$phase' of Null Ng-file-upload"
Post a Comment