Home Reference Source
import {File} from 'qiniup/src/file.js'
public class | source

File

文件类 能够统一文件类型,可以传入多种类型对象 能够保存文件分块分片信息到本地缓存中 通过哈希文件获取缓存中的文件以达到保存文件上传情况与断点续传等效果

Static Member Summary

Static Public Members
public static

File 默认配置

public static

Constructor Summary

Public Constructor
public

constructor(file: File | Blob | String, options: Object): File

创建一个文件对象

Member Summary

Public Members
public

[key]: *

public

blob: Blob

源文件转化成的 Blob 对象 将文件(File), 文件列表(Array[<File, File...>]), base64(String) 文件数据转换成 Blob 基础文件对象

public

file: File | Blob | String

源文件

public

文件哈希值,根据文件名文件大小文件类型与最后修改时间来确定; 如果源文件为字符串则直接将字符串进行哈希处理

public

配置

public get

size: Integer

文件大小

public

文件状态,用于存储文件上传信息

public

存储对象,主要用于本地存储

public

文件类型

Method Summary

Public Methods
public

cleanCache(hashCode: String)

删除文件上传信息的本地缓存

public

销毁对象

public

export(type: Integer, callback: Function): *

导出文件上传状态信息

public

getState(beginPos: Integer, endPos: Integer): Object

获取文件上传信息

public

import(source: Object | Json, callback: Function): *

导入文件上传状态信息

public

isUploaded(beginPos: Integer, endPos: Integer): Boolean

检测分块或者分片是否被上传

public

loadState(hashCode: String, callback: Function): *

从本地缓存中读取并导入文件上传状态信息

public

saveState(hashCode: String, callback: Function): *

导出并保存文件上传状态信息到本地缓存中

public

setState(beginPos: Integer, endPos: Integer, state: Object, cache: Boolean)

保存状态信息

public

slice(beginPos: Integer, endPos: Integer, type: String): Blob

文件切片,将文件切割成 Blob 文件段,开始位置与结束位置不能小于 0 并不能大于文件大小, 开始位置不能大于结束位置

Static Public Members

public static defaultSettings: Object source

File 默认配置

Properties:

NameTypeAttributeDescription
defaultSettings.mimeType String

文件类型,默认为 plain/text 文本类型

defaultSettings.chunkSize Integer

分片大小,默认为 4M,表示一片,虽然没有限制, 但是七牛官方文档表示分块(Block)为4M,最后一个分块(Block)也不能大于 4M, 因此分片不可能大于分块的大小,参考文档: https://developer.qiniu.com/kodo/api/1286/mkblk

defaultSettings.chunkInBlock Integer

分片数量,默认为 1

defaultSettings.cache Boolean

是否缓存

defaultSettings.expired Integer

过期时间,默认为一天 (1000 x 60 x 60 x 24),该事件为保存文件信息到本地缓存中缓存的过期时间

public static stateFormatter: * source

Public Constructors

public constructor(file: File | Blob | String, options: Object): File source

创建一个文件对象

Params:

NameTypeAttributeDescription
file File | Blob | String

需要上传的文件,可以为 Form 获取的 File 对象, 可以为 Blob,或者是 Base64 等字符串

options Object
  • optional
  • default: {}

配置,可以参考File.defaultSettings

options.mimeType String
  • optional
  • default: 'plain/text

文件类型,默认为 plain/text 文本类型

options.chunkSize Integer
  • optional
  • default: 4 * M

分片大小,默认为 4M,表示一片,虽然没有限制,但是七牛官方文档表示分块(Block)为4M, 最后一个分块(Block)也不能大于 4M,因此分片不可能大于分块的大小, 参考文档: https://developer.qiniu.com/kodo/api/1286/mkblk

options.chunkInBlock Integer

分片数量,默认为 1

options.expired Integer

过期时间,默认为一天 (1000 x 60 x 60 x 24),该事件为保存文件信息到本地缓存中缓存的过期时间

Return:

File

文件对象

Public Members

public [key]: * source

public blob: Blob source

源文件转化成的 Blob 对象 将文件(File), 文件列表(Array[<File, File...>]), base64(String) 文件数据转换成 Blob 基础文件对象

public file: File | Blob | String source

源文件

public hash: String source

文件哈希值,根据文件名文件大小文件类型与最后修改时间来确定; 如果源文件为字符串则直接将字符串进行哈希处理

public settings: Object source

配置

public get size: Integer source

文件大小

public state: Array<Object> source

文件状态,用于存储文件上传信息

public storage: Storage source

存储对象,主要用于本地存储

public type: String source

文件类型

Public Methods

public cleanCache(hashCode: String) source

删除文件上传信息的本地缓存

Params:

NameTypeAttributeDescription
hashCode String
  • optional
  • default: this.hash

文件哈希值,默认为读取文件的哈希值

public destory() source

销毁对象

public export(type: Integer, callback: Function): * source

导出文件上传状态信息

Params:

NameTypeAttributeDescription
type Integer
  • optional
  • default: this.constructor.stateFormatter.OBJECT

格式类型,具体值参考 File.stateFormatter

callback Function

回调函数,导出成功将返回数据

Return:

*

public getState(beginPos: Integer, endPos: Integer): Object source

获取文件上传信息

Params:

NameTypeAttributeDescription
beginPos Integer

起始位置

endPos Integer

结束位置

Return:

Object

信息数据

public import(source: Object | Json, callback: Function): * source

导入文件上传状态信息

Params:

NameTypeAttributeDescription
source Object | Json

上传状态信息数据

callback Function
  • optional

回调函数,成功导入将不会抛出异常,失败第一个参数将返回错误信息

Return:

*

public isUploaded(beginPos: Integer, endPos: Integer): Boolean source

检测分块或者分片是否被上传

Params:

NameTypeAttributeDescription
beginPos Integer

起始位置

endPos Integer

结束位置

Return:

Boolean

返回是否上传成功

public loadState(hashCode: String, callback: Function): * source

从本地缓存中读取并导入文件上传状态信息

Params:

NameTypeAttributeDescription
hashCode String
  • optional
  • default: this.hash

文件哈希值,默认为读取文件的哈希值

callback Function
  • optional

回调函数,错误会抛出错误异常

Return:

*

public saveState(hashCode: String, callback: Function): * source

导出并保存文件上传状态信息到本地缓存中

Params:

NameTypeAttributeDescription
hashCode String
  • optional
  • default: this.hash

文件哈希值,默认为读取文件的哈希值

callback Function
  • optional

回调函数,错误会抛出错误异常

Return:

*

public setState(beginPos: Integer, endPos: Integer, state: Object, cache: Boolean) source

保存状态信息

Params:

NameTypeAttributeDescription
beginPos Integer

起始位置

endPos Integer

结束位置

state Object

状态,保存的状态

cache Boolean
  • optional
  • default: this.settings.cache

是否缓存

public slice(beginPos: Integer, endPos: Integer, type: String): Blob source

文件切片,将文件切割成 Blob 文件段,开始位置与结束位置不能小于 0 并不能大于文件大小, 开始位置不能大于结束位置

Params:

NameTypeAttributeDescription
beginPos Integer

开始位置,默认为 0,位置必须大于 0, 且不能大于或等于结束位置

endPos Integer

结束位置,必须大于开始位置

type String
  • optional
  • default: this.type

类型,默认为文件的类型

Return:

Blob

分片文件