Assets

Description

The Assets API allows you to communicate with the Asset Browser.

Supported Script Types: Interface Scripts • Client Entity Scripts • Avatar Scripts • Server Entity Scripts • Assignment Client Scripts

Methods

Name Return Value Summary
canWriteCacheValue boolean
compressData None
decompressData None
deleteAsset None
downloadData None Download data from the connected domain's asset server.
extractAssetHash string
getAsset None Request Asset data from the ATP Server
getATPUrl string
getCacheStatus None
getMapping None Look up a path to hash mapping within the connected domain's asset server
hashData object
hashDataHex string
initializeCache boolean
isValidFilePath boolean
isValidHash boolean
isValidPath boolean
loadFromCache None
putAsset None Upload Asset data to the ATP Server
queryCacheMeta None
resolveAsset None
saveToCache None
saveToCache None
setBakingEnabled None
setMapping None Sets up a path to hash mapping within the connected domain's asset server
uploadData None Upload content to the connected domain's asset server.

Type Definitions

GetOptions
Type: object

A set of properties that can be passed to Assets.getAsset.

Properties

Name Type Attributes Summary
url string <optional>
an "atp:" style URL, hash, or relative mapped path to fetch
responseType string <optional>
the desired reponse type (text | arraybuffer | json)

Default Value: text

decompress boolean <optional>
whether to attempt gunzip decompression on the fetched data See: Assets.putAsset and its .compress=true option

Default Value: false

PutOptions
Type: object

A set of properties that can be passed to Assets.putAsset.

Properties

Name Type Attributes Summary
data ArrayBuffer | string <optional>
byte buffer or string value representing the new asset's content
path string <optional>
ATP path mapping to automatically create (upon successful upload to hash)

Default Value: null

compress boolean <optional>
whether to gzip compress data before uploading

Default Value: false

downloadDataCallback( data )
Type: function

Called when downloadData is complete

getAssetCallback( error, result )
Type: function

Called when Assets.getAsset is complete.

getAssetResult
Type: object

Result value returned by Assets.getAsset.

Properties

Name Type Attributes Summary
url string <optional>
the resolved "atp:" style URL for the fetched asset
hash string <optional>
the resolved hash for the fetched asset
response string | ArrayBuffer | Object <optional>
response data (possibly converted per .responseType value)
responseType string <optional>
response type (text | arraybuffer | json)
contentType string <optional>
detected asset mime-type (autodetected)
byteLength number <optional>
response data size in bytes
decompressed number <optional>
flag indicating whether data was decompressed
getMappingCallback( assetID, error )
Type: function

Called when getMapping is complete.

putAssetResult
Type: object

Result value returned by Assets.putAsset.

Properties

Name Type Attributes Summary
url string <optional>
the resolved "atp:" style URL for the uploaded asset (based on .path if specified, otherwise on the resulting ATP hash)
path string <optional>
the uploaded asset's resulting ATP path (or undefined if no path mapping was assigned)
hash string <optional>
the uploaded asset's resulting ATP hash
compressed boolean <optional>
flag indicating whether the data was compressed before upload
byteLength number <optional>
flag indicating final byte size of the data uploaded to the ATP server
puttAssetCallback( error, result )
Type: function

Called when Assets.putAsset is complete.

setBakingEnabledCallback( )
Type: function

Called when setBakingEnabled is complete.

setMappingCallback( error )
Type: function

Called when setMapping is complete

uploadDataCallback( url, hash )
Type: function

Called when uploadData is complete

Method Details

(static) canWriteCacheValue( url ) → {boolean}
Returns: boolean

Parameters

Name Type Description
url string
(static) compressData( options, scope, callbackopt )

Parameters

Name Type Attributes Default Value Description
options
scope
callback <optional>
""
(static) decompressData( options, scope, callbackopt )

Parameters

Name Type Attributes Default Value Description
options
scope
callback <optional>
""
(static) deleteAsset( options, scope, callbackopt )

Parameters

Name Type Attributes Default Value Description
options
scope
callback <optional>
""
(static) downloadData( url, callback )

Download data from the connected domain's asset server.

Parameters

Name Type Description
url string URL of asset to download, must be ATP scheme URL.
callback Assets~downloadDataCallback
(static) extractAssetHash( input ) → {string}
Returns: string

Parameters

Name Type Description
input string
(static) getAsset( options, scope, callbackopt )

Request Asset data from the ATP Server

Parameters

Name Type Attributes Description
options URL | Assets.GetOptions An atp: style URL, hash, or relative mapped path; or an Assets.GetOptions object with request parameters
scope Assets~getAssetCallback A scope callback function to receive (error, results) values
callback function <optional>
(static) getATPUrl( input ) → {string}
Returns: string

Parameters

Name Type Description
input string
(static) getCacheStatus( scope, callbackopt )

Parameters

Name Type Attributes Description
scope
callback <optional>
(static) getMapping( path, callback )

Look up a path to hash mapping within the connected domain's asset server

Parameters

Name Type Description
path string
callback Assets~getMappingCallback
(static) hashData( data ) → {object}
Returns: object

Parameters

Name Type Description
data
(static) hashDataHex( data ) → {string}
Returns: string

Parameters

Name Type Description
data
(static) initializeCache( ) → {boolean}
Returns: boolean

(static) isValidFilePath( input ) → {boolean}
Returns: boolean

Parameters

Name Type Description
input string
(static) isValidHash( input ) → {boolean}
Returns: boolean

Parameters

Name Type Description
input string
(static) isValidPath( input ) → {boolean}
Returns: boolean

Parameters

Name Type Description
input string
(static) loadFromCache( options, scope, callbackopt )

Parameters

Name Type Attributes Description
options
scope
callback <optional>
(static) putAsset( options, scope[callback, callbackopt )

Upload Asset data to the ATP Server

Parameters

Name Type Attributes Description
options Assets.PutOptions A PutOptions object with upload parameters
scope[callback Assets~putAssetCallback A scoped callback function invoked with (error, results)
callback function <optional>
(static) queryCacheMeta( options, scope, callbackopt )

Parameters

Name Type Attributes Description
options
scope
callback <optional>
(static) resolveAsset( options, scope, callbackopt )

Parameters

Name Type Attributes Default Value Description
options
scope
callback <optional>
""
(static) saveToCache( url, data, metadata, scope, callbackopt )

Parameters

Name Type Attributes Description
url
data
metadata
scope
callback <optional>
(static) saveToCache( options, scope, callbackopt )

Parameters

Name Type Attributes Description
options
scope
callback <optional>
(static) setBakingEnabled( path, enabled, callback )

Parameters

Name Type Description
path string
enabled boolean
callback
(static) setMapping( path, hash, callback )

Sets up a path to hash mapping within the connected domain's asset server

Parameters

Name Type Description
path string
hash string
callback Assets~setMappingCallback
(static) uploadData( data, callback )

Upload content to the connected domain's asset server.

Parameters

Name Type Description
data string content to upload
callback Assets~uploadDataCallback called when upload is complete