angular-file-upload 中文API

github地址: https://github.com/nervgh/angular-file-upload

Directives(指令)

  • nv-file-drop

<pre style="margin: 0px; padding: 0px;">
<elementnv-file-dropuploader="{FileUploader}"></element>

<elementnv-file-dropuploader="{FileUploader}"options="{Object}"filters="{String}"></element></pre>

属性 uploader 必须是 FileUploader的一个实例。
属性 **options **可能是 {FileItem} 的设置或者自定义设置。
属性 **filters **可能是用,隔开的过滤器名称,比如: 'filterName1, filterName2',这些过滤器必须如下预定义:

<pre style="margin: 0px; padding: 0px;">uploader.filters.push({name:'filterName1', fn:function() {/* your code here /}});
uploader.filters.push({name:'filterName2', fn:function() {/
your code here */}});</pre>

  • nv-file-select

<pre style="margin: 0px; padding: 0px;">
<inputtype="file"nv-file-selectuploader="{FileUploader}"/>

<input type="file"nv-file-selectuploader="{FileUploader}" options="{Object}" filters="{String}"/>

  • nv-file-over

<pre style="margin: 0px; padding: 0px;">
<elementnv-file-overuploader="{FileUploader}"></element>

<elementnv-file-overuploader="{FileUploader}"over-class="{String}"></element></pre>

Service(服务)

FileUploader
属性

url {String}: 上传文件的服务器路径
alias {String}: 包含文件的名称,默认是file
queue {Array}: 上传队列
progress {Number}: 上传队列的进度,只读
headers {Object}: 上传的头文件信息, 浏览器需支持HTML5
formData {Array}: 与文件一起发送的表单数据
filters {Array}: 在文件加入上传队列之前应用过滤器.,如果过滤器返回true则文件加入队列中
autoUpload {Boolean}: 文件加入队列之后自动上传,默认是false
method {String}: 请求方式,默认是POST,浏览器需支持HTML5
removeAfterUpload {Boolean}: 文件上传成功之后从队列移除,默认是false
isHTML5 {Boolean}: 如果浏览器支持HTML5上传则返回true,只读
isUploading {Boolean}: 文件正在上传中返回true,只读
queueLimit {Number} : 最大上传文件数量(预定义)
withCredentials {Boolean} : 使用CORS,默认是false, 浏览器需支持HTML5

方法

addToQueue function(files[, options[, filters]]) {: Add items to the queue, where files is a {FileList|File|HTMLInputElement}, options is an {Object} andfilters is a {String}. 添加项到上传队列中,files 是 {FileList|File|HTMLInputElement}, options 是 {Object} 以及 filters 是 {String}
removeFromQueue function(value) {: Remove an item from the queue, wherevalue is {FileItem} or index of item. 从上传队列移除项,value 可以是 {FileItem} 或者项的序号
clearQueue function() {: Removes all elements from the queue. 移除上传队列所有的元素
uploadItem function(value) {: Uploads an item, where value is {FileItem} or index of item. 上传项, value 可以是 {FileItem} 或者项的序号
cancelItem function(value) {: Cancels uploading of item, where value is{FileItem} or index of item. 取消上传的项
uploadAll function() {: Upload all pending items on the queue. 将上传队列中所有的项进行上传
cancelAll function() {: Cancels all current uploads. 取消所有当前上传
destroy function() {: Destroys a uploader.
isFile function(value) {return {Boolean};}: Returns true if value is {File}.
isFileLikeObject function(value) {return {Boolean};}: Returns true if value is{FileLikeObject}.
getIndexOfItem function({FileItem}) {return {Number};}: Returns the index of the{FileItem} queue element. 返回项在上传队列中的序号
getReadyItems function() {return {Array.<FileItems>};}: Return items are ready to upload. 返回准备上传的项
getNotUploadedItems function() {return {Array.<FileItems>};}: Return an array of all pending items on the queue 返回上传队列中未上传的项

回调函数

onAfterAddingFile function(item) {: 添加文件到上传队列后
onWhenAddingFileFailed function(item, filter, options) {: 添加文件到上传队列失败后
onAfterAddingAll function(addedItems) {: 添加所选的所有文件到上传队列后
onBeforeUploadItem function(item) {: 文件上传之前
onProgressItem function(item, progress) {: 文件上传中
onSuccessItem function(item, response, status, headers) {: 文件上传成功后
onErrorItem function(item, response, status, headers) {: 文件上传失败后
onCancelItem function(item, response, status, headers) { - 文件上传取消后
onCompleteItem function(item, response, status, headers) {: 文件上传完成后
onProgressAll function(progress) {: 上传队列的所有文件上传中
onCompleteAll function() {: 上传队列的所有文件上传完成后

成功上传文件的回调函数顺序是:onAfterAddingFile — onAfterAddingAll — onBeforeUploadItem — onProgressItem — onProgressAll — onSuccessItem — onCompleteItem — onCompleteAll

FileItem

属性

url {String}: Path on the server in which this file will be uploaded 上传文件的服务器路径
alias {String}: Name of the field which will contain the file, default is file 包含文件的名称,默认是file
headers {Object}: Headers to be sent along with this file. HTML5 browsers only. 上传的头文件信息, 浏览器需支持HTML5
formData {Array}: Data to be sent along with this file 与文件一起发送的表单数据
method {String}: It's a request method. By default POST. HTML5 browsers only. 请求方式,默认是POST,浏览器需支持HTML5
withCredentials {Boolean} : enable CORS. HTML5 browsers only. 使用CORS,默认是false, 浏览器需支持HTML5
removeAfterUpload {Boolean}: Remove this file from the queue after uploading 上传之后从上传队列移除该文件
index {Number} - A sequence number upload. Read only. 上传文件在上传队列中的序号,只读
progress {Number}: File upload progress percentage. Read only. 文件上传的进度,只读
isReady {Boolean} - File is ready to upload. Read only. 文件是否准备好上传,只读
isUploading {Boolean}: true if the file is being uploaded. Read only. 文件是否正在上传中,只读
isUploaded {Boolean}: true if the file was uploaded. Read only. 文件是否已经上传,只读
isSuccess {Boolean}: true if the file was uploaded successfully. Read only. 文件是否已经上传成功,只读
isCancel {Boolean} : true if uploading was canceled. Read only. 文件是否取消上传,只读
isError {Boolean} - true if occurred error while file uploading. Read only. 文件是否上传错误,只读
uploader {Object}: Reference to the parent Uploader object for this file. Read only. 上传该文件的Uploader ,只读

方法

remove function() {: Remove this file from the queue 从上传队列移除该文件
upload function() {: Upload this file 上传该文件
cancel function() {: Cancels uploading of this file 取消上传该文件

回调函数

onBeforeUpload function() {: Fires before uploading an item. 上传该文件之前
onProgress function(progress) {: On file upload progress. 上传该文件的过程
onSuccess function(response, status, headers) {: On file successfully uploaded 成功上传该文件后
onError function(response, status, headers) {: On upload error 上传该文件出错后
onCancel function(response, status, headers) { - On cancel uploading 取消上传该文件后
onComplete function(response, status, headers) {: On file upload complete (independently of the sucess of the operation) 完成上传该文件后

Filters(过滤器)

注册过滤器:
var uploader =newFileUploader({
filters: [{
name:'yourName1',
// A user-defined filterfn:function(item) {
returntrue;
}
}]
});

// 另一种
uploader.filters.push({
name:'yourName2',
fn:function(item) {
returntrue;
}
});
预定义的过滤器:
folder
queueLimit

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 159,716评论 4 364
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,558评论 1 294
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 109,431评论 0 244
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 44,127评论 0 209
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,511评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,692评论 1 222
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,915评论 2 313
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,664评论 0 202
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,412评论 1 246
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,616评论 2 245
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,105评论 1 260
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,424评论 2 254
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,098评论 3 238
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,096评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,869评论 0 197
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,748评论 2 276
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,641评论 2 271