Skip to main content

CloudStorageModule

Class

Provides access to Cloud Storage capabilities.

  • Available on all platforms
Platform details: Snapchat, SPECS, Camera Kit Web, Camera Kit Mobile fully supported.

Platform details

  • Snapchat — Fully supported.

  • SPECS — Fully supported.

  • Camera Kit Web — Fully supported.

  • Camera Kit Mobile — Fully supported.

Since Lens Scripting v173

Not available on SPECS. Use Snap Cloud for persistence there instead.

Index

Mobile Only

Example

// Check out Persistent Cloud Storage example in the Asset Library

const cloudStorageOptions = CloudStorageOptions.create();

script.cloudStorageModule.getCloudStore(
cloudStorageOptions,
onCloudStoreReady,
onError
);

function onCloudStoreReady(store) {

// Write
const writeOptions = CloudStorageWriteOptions.create();
writeOptions.scope = StorageScope.User;

store.setValue(
"myKey",
"myValue",
writeOptions,
function onSuccess() {
print("Stored Succesfully!");

// List
const listOptions = CloudStorageListOptions.create();
listOptions.scope = StorageScope.User;

store.listValues(
listOptions,
function(results, cursor) {
// Results are returned as a list of [key, value] tuples
for (var i = 0; i < results.length; ++i) {
var key = results[i][0];
var value = results[i][1];
print(' - key: ' + key + ' value: ' + value);
}
},
onError
);

},
onError
);
}

function onError(code, message) {
print('Error: ' + code + ' ' + message);
}

Extends

Properties

name

name: string

The name of the Asset in Lens Studio.

Default Value

""

Inherited from

Asset.name


uniqueIdentifier

readonly uniqueIdentifier: string

Since

Lens Scripting Version 176

Inherited from

Asset.uniqueIdentifier

Methods

getCloudStore()

getCloudStore(options, onCloudStoreReady, onError): void

Get the Cloud Store. Future calls to this method will return the same cloud store, even if the options change.

Parameters

ParameterType
optionsCloudStorageOptions
onCloudStoreReady(store) => void
onError(code, description) => void

Returns

void

Since

Lens Scripting Version 173

Mobile Only


getTypeName()

static getTypeName(): TypeName<CloudStorageModule>

Returns the fully-qualified JavaScript type name for this class (for example, "Component.Camera"). This is a static accessor (no instance required) and returns the same value as the instance getTypeName().

Returns

TypeName<CloudStorageModule>

Since

Lens Scripting Version 173

Mobile Only

Overrides

Asset.getTypeName


getTypeName()

getTypeName(): string

Returns the name of this object's type.

Returns

string

Inherited from

Asset.getTypeName


isOfType()

isOfType(type): boolean

Returns true if the object matches or derives from the passed in type.

Parameters

ParameterType
typestring

Returns

boolean

Inherited from

Asset.isOfType


isSame()

isSame(other): boolean

Returns true if this object is the same as other. Useful for checking if two references point to the same thing.

Parameters

ParameterType
otherScriptObject

Returns

boolean

Inherited from

Asset.isSame

See also

Cloud Storage Overview.