MLFile Class Reference

Inherits from NSObject
Conforms to NSSecureCoding
Declared in MLFile.h

Overview

A file of binary data stored on the MaxLeap servers. This can be a image, video, or anything else that an application needs to reference in a non-relational way.

Creating a MLFile

+ fileWithData:

Creates a file with given data. A name will be assigned to it by the server.

+ (instancetype)fileWithData:(NSData *)data

Parameters

data

The contents of the new MLFile.

Return Value

A MLFile.

Declared In

MLFile.h

+ fileWithName:data:

Creates a file with given data and name.

+ (instancetype)fileWithName:(nullable NSString *)name data:(NSData *)data

Parameters

name

The name of the new MLFile.

data

The contents of hte new MLFile.

Return Value

A MLFile.

Declared In

MLFile.h

+ fileWithName:contentsAtPath:

Creates a file with the contents of another file.

+ (instancetype)fileWithName:(nullable NSString *)name contentsAtPath:(NSString *)path

Parameters

name

The name of the new MLFile

path

The path to the file that will be uploaded to MaxLeap

Declared In

MLFile.h

+ fileWithUrl:

Create a file with url.

+ (instancetype)fileWithUrl:(NSString *)url

Parameters

url

The url

Return Value

A MLFile object.

Declared In

MLFile.h

  name

The name of the file.

@property (readonly, copy, nullable) NSString *name

Declared In

MLFile.h

  url

The url of the file.

@property (readonly, copy, nullable) NSString *url

Declared In

MLFile.h

  isDirty

Whether the file has been uploaded for the first time.

@property (readonly) BOOL isDirty

Declared In

MLFile.h

  isDataAvailable

Whether the data is available in memory or needs to be downloaded.

@property (readonly) BOOL isDataAvailable

Declared In

MLFile.h

Storing Data with MaxLeap

– saveInBackgroundWithBlock:

Saves the file asynchronously and executes the given block.

- (void)saveInBackgroundWithBlock:(nullable MLBooleanResultBlock)block

Parameters

block

The block should have the following argument signature: (BOOL succeeded, NSError *error)

Declared In

MLFile.h

– saveInBackgroundWithBlock:progressBlock:

Saves the file asynchronously and executes the given resultBlock. Executes the progressBlock periodically with the percent progress. progressBlock will get called with 100 before resultBlock is called.

- (void)saveInBackgroundWithBlock:(nullable MLBooleanResultBlock)block progressBlock:(nullable MLProgressBlock)progressBlock

Parameters

block

The block should have the following argument signature: (BOOL succeeded, NSError *error)

progressBlock

The block should have the following argument signature: (int percentDone)

Declared In

MLFile.h

Getting Data from MaxLeap

– getData:

Synchronously gets the data from cache if available or fetches its contents from the MaxLeap servers. Sets an error if it occurs.

- (nullable NSData *)getData:(NSError *__nullable *__nullable)error

Parameters

error

Pointer to an NSError that will be set if necessary.

Return Value

The data of file. Returns nil if there was an error in fetching.

Declared In

MLFile.h

– getDataInBackgroundWithBlock:

Asynchronously gets the data from cache if available or fetches its contents from the MaxLeap servers. Executes the given block.

- (void)getDataInBackgroundWithBlock:(nullable MLDataResultBlock)block

Parameters

block

The block should have the following argument signature: (NSData result, NSError error)

Declared In

MLFile.h

– getDataStreamInBackgroundWithBlock:

This method is like getDataInBackgroundWithBlock: but avoids ever holding the entire MLFile’s contents in memory at once. This can help applications with many large MLFiles avoid memory warnings.

- (void)getDataStreamInBackgroundWithBlock:(nullable MLDataStreamResultBlock)block

Parameters

block

The block should have the following argument signature: (NSInputStream result, NSError error)

Declared In

MLFile.h

– getDataInBackgroundWithBlock:progressBlock:

Asynchronously gets the data from cache if available or fetches its contents from the MaxLeap servers. Executes the resultBlock upon completion or error. Executes the progressBlock periodically with the percent progress. progressBlock will get called with 100 before resultBlock is called.

- (void)getDataInBackgroundWithBlock:(nullable MLDataResultBlock)resultBlock progressBlock:(nullable MLProgressBlock)progressBlock

Parameters

resultBlock

The block should have the following argument signature: (NSData result, NSError error)

progressBlock

The block should have the following argument signature: (int percentDone)

Declared In

MLFile.h

– getDataStreamInBackgroundWithBlock:progressBlock:

This method is like getDataInBackgroundWithBlock:progressBlock: but avoids ever holding the entire MLFile’s contents in memory at once. This can help applications with many large MLFiles avoid memory warnings.

- (void)getDataStreamInBackgroundWithBlock:(nullable MLDataStreamResultBlock)resultBlock progressBlock:(nullable MLProgressBlock)progressBlock

Parameters

resultBlock

The block should have the following argument signature: (NSInputStream result, NSError error)

progressBlock

The block should have the following argument signature: (int percentDone)

Declared In

MLFile.h

Interrupting a Transfer

– cancel

Cancels the current request (whether upload or download of file data).

- (void)cancel

Declared In

MLFile.h

Other Methods

+ getFileInBackgroundWithName:block:

Get file with specified name.

+ (void)getFileInBackgroundWithName:(NSString *)name block:(nullable MLFileResultBlock)block

Parameters

name

The name of a file.

block

The block will execute on main thread.

Declared In

MLFile.h

+ getAllInBackgroundWithBlock:

Get all files uploaded by current user.

+ (void)getAllInBackgroundWithBlock:(nullable MLArrayResultBlock)block

Parameters

block

The callback, will be executed on main thread. The block should have the following argument signature: (NSArray files, NSError error).

Declared In

MLFile.h