FileLoader

A low level class for loading resources with the Fetch API, used internally by most loaders. It can also be used directly to load any file type that does not have a loader.

const loader = new FileLoader();
const data = await loader.loadAsync('example.txt');

Constructor

new FileLoader(manageropt)

Constructs a new file loader.

Parameters:
NameTypeAttributesDescription
managerLoadingManager<optional>

The loading manager.

Extends

Members

crossOrigin :string

The crossOrigin string to implement CORS for loading the url from a different domain that allows CORS.

Type:
  • string
Default Value
  • 'anonymous'

manager :LoadingManager

The loading manager.

Default Value
  • DefaultLoadingManager

mimeType :string

The expected mimeType. See FileLoader.setMimeType.

Type:
  • string
Default Value
  • ''

path :string

The base path from which the asset will be loaded.

Type:
  • string
Overrides
Default Value
  • ''

requestHeader :object

The request header used in HTTP request.

Type:
  • object
Default Value
  • {}

responseType :'arraybuffer'|'blob'|'document'|'json'|''

The expected response type. See FileLoader.setResponseType.

Type:
  • 'arraybuffer' | 'blob' | 'document' | 'json' | ''
Default Value
  • ''

withCredentials :boolean

Whether the XMLHttpRequest uses credentials.

Type:
  • boolean
Default Value
  • false

Methods

load(url, onLoadopt, onProgressopt, onErroropt)

Starts loading from the given URL and pass the loaded response to the onLoad() callback.

Parameters:
NameTypeAttributesDescription
urlstring

— The path/URL of the file to be loaded. This can also be a data URI.

onLoadfunction<optional>

— Executed when the loading process has been finished. The argument is the loaded data.

onProgressonProgressCallback<optional>

— Executed while the loading is in progress.

onErroronErrorCallback<optional>

— Executed when errors occur.

Overrides

loadAsync(url, onProgressopt) → {Promise}

A async version of Loader#load.

Parameters:
NameTypeAttributesDescription
urlstring

The path/URL of the file to be loaded.

onProgressfunction<optional>

Executed while the loading is in progress.

Returns:

A Promise that resolves when the asset has been loaded.

Type: 
Promise

setCrossOrigin(crossOrigin) → {Loader}

Sets the crossOrigin String to implement CORS for loading the URL from a different domain that allows CORS.

Parameters:
NameTypeDescription
crossOriginstring

The crossOrigin value.

Returns:

A reference to this instance.

Type: 
Loader

setMimeType(value) → {FileLoader}

Sets the expected mime type of the loaded file.

Parameters:
NameTypeDescription
valuestring

The mime type.

Returns:

A reference to this file loader.

Type: 
FileLoader

setPath(path) → {Loader}

Sets the base path for the asset.

Parameters:
NameTypeDescription
pathstring

The base path.

Returns:

A reference to this instance.

Type: 
Loader

setRequestHeader(requestHeader) → {Loader}

Sets the given request header.

Parameters:
NameTypeDescription
requestHeaderobject

A request header for configuring the HTTP request.

Returns:

A reference to this instance.

Type: 
Loader

setResponseType(value) → {FileLoader}

Sets the expected response type.

Parameters:
NameTypeDescription
value'arraybuffer' | 'blob' | 'document' | 'json' | ''

The response type.

Returns:

A reference to this file loader.

Type: 
FileLoader

setWithCredentials(value) → {Loader}

Whether the XMLHttpRequest uses credentials such as cookies, authorization headers or TLS client certificates, see XMLHttpRequest.withCredentials. Note: This setting has no effect if you are loading files locally or from the same domain.

Parameters:
NameTypeDescription
valueboolean

The withCredentials value.

Returns:

A reference to this instance.

Type: 
Loader