FileTransfer插件

提供文件的上传和下载功能

[!WARNING]

  • 插件的所有接口在 deviceready 事件后生效;

FileTransfer对象方法与属性

FileTransfer对象提供了使用HTTP multi-par POSTPUT请求上传文件并下载文件的方法。以下两个表分别为FileTransfer提供的方法和属性。

方法 说明
upload 将文件发送到服务器
download 从服务器下载文件
abort 中止正在进行的转移
resolveLocalFileSystemURL file:// 与 cdvfile://文件URI路径转换
属性 类型 说明
onProgress Function 进度信息,每当传输新的数据块时调用,返回参数为ProgressEvent对象

属性列表

ProgressEvent对象属性:

参数 类型 说明
lengthComputable Boolean 文件大小是否可知,true表示可知,false表示不可知
loaded Number 已下载大小(B)
total Number 文件大小(B)

FileUploadOptions对象属性:

参数 类型 说明
fileKey DOMString 表单元素的名称,默认为file
fileName DOMString 在服务器上保存文件时使用的文件名,默认为image.jpg
httpMethod DOMString 要使用的HTTP方法PUTPOST,默认为POST
mimeType DOMString 要上传的数据的MIME类型,默认为image/jpeg
params Object 在HTTP请求中传递的一组可选键/值对,key/value-DOMString
headers Object 标题名称/标题值的映射,使用数组来制定多个值。在iosAndroid上,如果存在名为Content-Type的标头,则不会使用多部分表单数据

FileUploadResult对象属性:(FileTransfer对象调用upload成功后的回调函数传递值)

参数 类型 说明 Android iOS
bytesSent Number 作为上传的一部分发送到服务器的字节数 支持 不支持
responseCode Number 服务器返回的HTTP相应代码 支持 不支持
httpMethod DOMString 服务器返回的HTTP响应 支持 支持
headers Object 服务器的HTTP相应标头 不支持 支持

FileTransferError对象属性:

参数 类型 说明
code Number 错误代码之一: 1 = FileTransferError.FILE_NOT_FOUND_ERR 2 = FileTransferError.INVALID_URL_ERR 3 = FileTransferError.CONNECTION_ERR 4 = FileTransferError.ABORT_ERR 5 = FileTransferError.NOT_MODIFIED_ERR
source String 到源的URL
target String 到目标的URL
http_status Number HTTP状态码。该属性仅在从HTTP连接接收到相应代码时可用
body String 响应body,该属性仅在从HTTP连接收到相应时可用
exception String 异常信息

FileEntry对象属性:

参数 类型 说明 Android iOS
name DOMString 文件名称 支持 不支持
fullPath Number 文件的绝对路径(不含file:///) 支持 不支持
fileSystem DOMString 文件系统 支持 支持
nativeURL Object 文件本地路径(含file:///) 不支持 支持

Mime 类型列表

扩展名 mimeType
acx application/internet-property-stream
ai、ps、eps、ps application/postscript
aif、aifc、aiff audio/x-aiff
asf、asr、asx video/x-ms-asf
au audio/basic
avi video/x-msvideo
axs application/olescript
bas、c、h、txt text/plain
bcpio application/x-bcpio
bin、dms、exe application/octet-stream
bmp image/bmp
cat application/vnd.ms-pkiseccat
cdf application/x-cdf
cer、crt、der application/x-x509-ca-cert
class application/octet-stream
clp application/x-msclip
cmx image/x-cmx
cod image/cis-cod
cpio application/x-cpio
crd application/x-mscardfile
crl application/pkix-crl
csh application/x-csh
css text/css
dcr、dir、dxr application/x-director
dll application/x-msdownload
doc、dot application/msword
dvi application/x-dvi
etx text/x-setext
evy application/envoy
fif application/fractals
flr、vrml、wrl、wrz、xaf、xof x-world/x-vrml
gif image/gif
gtar application/x-gtar
gz application/x-gzip
hdf application/x-hdf
hlp application/winhlp
hqx application/mac-binhex40
hta application/hta
htc text/x-component
htm、html、stm text/html
htt text/webviewhtml
ico image/x-icon
ief image/ief
iii application/x-iphone
ins、isp application/x-internet-signup
jfif image/pipeg
jpe、jpeg、jpg image/jpeg
js application/x-javascript
latex application/x-latex
lha 、lzh application/octet-stream
lsf、lsx video/x-la-asf
m13、m14、mvb application/x-msmediaview
m3u audio/x-mpegurl
man application/x-troff-man
mdb application/x-msaccess
me application/x-troff-me
mht、mhtml、nws message/rfc822
mid、rmi audio/mid
mny application/x-msmoney
mov、qt video/quicktime
movie video/x-sgi-movie
mp2、mpa、mpe、mpeg、mpg、mpv2 video/mpeg
mp3 audio/mpeg
mpp application/vnd.ms-project
ms application/x-troff-ms
msg application/vnd.ms-outlook
oda application/oda
p10 application/pkcs10
p12、pfx application/x-pkcs12
p7b、spc application/x-pkcs7-certificates
p7c、p7m application/x-pkcs7-mime
p7r application/x-pkcs7-certreqresp
p7s application/x-pkcs7-signature
pbm image/x-portable-bitmap
pdf application/pdf
pgm image/x-portable-graymap
pko application/ynd.ms-pkipko
pma、pmc、pml、pmr、pmw application/x-perfmon
pnm image/x-portable-anymap
pot、pps、ppt application/vnd.ms-powerpoint
ppm image/x-portable-pixmap
prf application/pics-rules
pub application/x-mspublisher
rtf application/rtf
ra、ram audio/x-pn-realaudio
ras image/x-cmu-raster
rgb image/x-rgb
roff、t、tr application/x-troff
rtx text/richtext
scd application/x-msschedule
sct text/scriptlet
setpay application/set-payment-initiation
setreg application/set-registration-initiation
sh application/x-sh
shar application/x-shar
sit application/x-stuffit
snd audio/basic
spl application/futuresplash
src application/x-wais-source
sst application/vnd.ms-pkicertstore
stl application/vnd.ms-pkistl
svg image/svg+xml
sv4cpio application/x-sv4cpio
sv4crc application/x-sv4crc
swf application/x-shockwave-flash
tar application/x-tar
tcl application/x-tcl
tex application/x-tex
texi、texinfo application/x-texinfo
tgz application/x-compressed
tif、tiff image/tiff
trm application/x-msterminal
tsv text/tab-separated-values
uls text/iuls
ustar application/x-ustar
vcf text/x-vcard
wav audio/x-wav
wcm、wdb、wks application/vnd.ms-works
wmf、wps application/x-msmetafile
wri application/x-mswrite
xbm image/x-xbitmap
xla、xlc、xlm、xls、xlt、xlw application/vnd.ms-excel
xpm image/x-xpixmap
xwd image/x-xwindowdump
z application/x-compress
zip application/zip

results matching ""

    No results matching ""