MLPrivateFile Class Reference

Inherits from NSObject
Declared in MLPrivateFile.h

Overview

A MaxLeap Framework object that represents metadata of private file.

Creating a Private File

– initWithLocalFileAtPath:remotePath:

Initialize a privateFile with localPath and remotePath.

- (instancetype)initWithLocalFileAtPath:(nullable NSString *)localPath remotePath:(NSString *)remotePath

Parameters

localPath

The path of the file on local disk.

remotePath

The path of the file on remote server, shouldn’t be nil.

Return Value

A private file instance.

Declared In

MLPrivateFile.h

– initWithLocalPath:remotePath:

Initialize a privateFile with localPath and remotePath.

- (instancetype)initWithLocalPath:(nullable NSString *)localPath remotePath:(NSString *)remotePath

Parameters

localPath

The path of the file on local disk.

remotePath

The path of the file on remote server, shouldn’t be nil.

Return Value

A private file instance.

Declared In

MLPrivateFile.h

+ fileWithRemotePath:

Create a privateFile with remotePath.

+ (instancetype)fileWithRemotePath:(NSString *)remotePath

Parameters

remotePath

The path of the file on remote server, shouldn’t be nil.

Return Value

A private file instance

Declared In

MLPrivateFile.h

Properties - File Metadata

  size

A formated string representing the item size, eg: “1.1 MB”, “832.5 KB”.

@property (nonatomic, readonly, nullable) NSString *size

Declared In

MLPrivateFile.h

  bytes

A number indicates the size of item in bytes.

@property (nonatomic, readonly) NSUInteger bytes

Declared In

MLPrivateFile.h

  MIMEType

The file’s MIMEType.

@property (nonatomic, readonly, nullable) NSString *MIMEType

Declared In

MLPrivateFile.h

  fileHash

Hash of the source file.

@property (nonatomic, copy, nullable) NSString *fileHash

Declared In

MLPrivateFile.h

  createdAt

When the file or directory was created.

@property (nonatomic, readonly, nullable) NSDate *createdAt

Declared In

MLPrivateFile.h

  updatedAt

When the file or directory was last updated.

@property (nonatomic, readonly, nullable) NSDate *updatedAt

Declared In

MLPrivateFile.h

  remotePath

The item’s path on remote server.

@property (nonatomic, readonly) NSString *remotePath

Declared In

MLPrivateFile.h

  localPath

The local path of the item.

@property (nonatomic, copy, nullable) NSString *localPath

Declared In

MLPrivateFile.h

  isDirectory

Whether this item is a directory.

@property (nonatomic, readonly) BOOL isDirectory

Declared In

MLPrivateFile.h

  contents

The contents of the dir. If this item is not a directory, contents is nil.

@property (nonatomic, readonly, nullable) NSArray *contents

Declared In

MLPrivateFile.h

  isDeleted

Whether the item is deleted from remote server.

@property (nonatomic, readonly) BOOL isDeleted

Declared In

MLPrivateFile.h

  isShared

Whether the item is shared from another user.

@property (nonatomic, readonly) BOOL isShared

Declared In

MLPrivateFile.h

  shareFrom

The id of user who shared this item.

@property (nonatomic, readonly, nullable) NSString *shareFrom

Declared In

MLPrivateFile.h

  url

The share url.

@property (nonatomic, readonly, nullable) NSURL *url

Declared In

MLPrivateFile.h

Upload Private Files

– saveInBackgroundWithBlock:

Asynchronously upload file at file.localPath to MaxLeap file servers.

- (void)saveInBackgroundWithBlock:(nullable MLBooleanResultBlock)block

Parameters

block

Block to excute on main thread after uploading file, it should have the following argument signature: (BOOL success, NSError *error)

Discussion

@disscussion If the file’s fileHash is not set, the md5 of file will be calculated and used. If file exists on remote path, the uploading will fail with a kMLErrorPathTaken error.

Declared In

MLPrivateFile.h

– saveAndOverwriteInBackgroundWithBlock:

Asynchronously upload file at file.localPath and save at the file.remotePath on MaxLeap file servers.

- (void)saveAndOverwriteInBackgroundWithBlock:(nullable MLBooleanResultBlock)block

Parameters

block

Block to excute on main thread after uploading file, it should have the following argument signature: (BOOL success, NSError *error)

Discussion

@disscussion If the file’s fileHash is not set, the md5 of file will be calculated and used. If file exists on remote path, it will be overwrite.

Declared In

MLPrivateFile.h

– saveInBackgroundWithBlock:progressBlock:

Asynchronously upload file at file.localPath and save at the file.remotePath on MaxLeap file servers.

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

Parameters

block

Block to excute on main thread after uploading file, it should have the following argument signature: (BOOL success, NSError *error)

progressBlock

Block to notify the upload progress, it should have the following argument signature: (int percentDone)

Discussion

@disscussion If the file’s fileHash is not set, the md5 of file will be calculated and used. If file exists on remote path, the uploading will fail with a kMLErrorPathTaken error.

Declared In

MLPrivateFile.h

– saveAndOverwriteInBackgroundWithBlock:progressBlock:

Asynchronously upload file at file.localPath and save at the file.remotePath on MaxLeap file servers.

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

Parameters

block

Block to excute on main thread after uploading file, it should have the following argument signature: (BOOL success, NSError *error)

progressBlock

Block to notify the upload progress, it should have the following argument signature: (int percentDone)

Discussion

@disscussion If the file’s fileHash is not set, the md5 of file will be calculated and used. If file exists on remote path, it will be overwrite.

Declared In

MLPrivateFile.h

Download Private Files

– downloadInBackgroundWithBlock:

Download and save the data at file.localPath. If the local path is nil, default path will be used.

- (void)downloadInBackgroundWithBlock:(nullable MLBooleanResultBlock)block

Parameters

block

Block to excute after file downloading. It should have the following argument signature: (NSString filePath, NSError error)

Declared In

MLPrivateFile.h

– downloadInBackgroundWithBlock:progressBlock:

Download and save the data at file.localPath. If the local path is nil, default path will be used.

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

Parameters

block

Block to excute after file downloading. It should have the following argument signature: (NSString filePath, NSError error)

progressBlock

Block to notify the upload progress, it should have the following argument signature: (int percentDone)

Declared In

MLPrivateFile.h

– cancel

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

- (void)cancel

Declared In

MLPrivateFile.h

Delete Private Files

– deleteInBackgroundWithBlock:

Delete the file at file.remotePath from remote server.

- (void)deleteInBackgroundWithBlock:(nullable MLBooleanResultBlock)block

Parameters

block

Block to excute after deleting, it should have the following argument signature: (BOOL success, NSError *error)

Declared In

MLPrivateFile.h

+ deletePathInBackground:block:

Delete the file at the path from remote server.

+ (void)deletePathInBackground:(NSString *)path block:(nullable MLBooleanResultBlock)block

Parameters

path

the remote path to delete

block

Block to excute after deleting, it should have the following argument signature: (BOOL success, NSError *error)

Declared In

MLPrivateFile.h

+ deleteAllInBackground:block:

Deletes a collection of files all at once asynchronously and excutes the block when done.

+ (void)deleteAllInBackground:(nullable NSArray ML_GENERIC ( NSString *) *)filePaths block:(void ( ^ ) ( BOOL isAllDeleted , NSArray ML_GENERIC ( NSString *) *deleted , NSError *__nullable error ))block

Parameters

filePaths

The remote paths of files to delete.

block

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

Declared In

MLPrivateFile.h

Get Metadata of a Private File

– getMetadataInBackgroundWithBlock:

Gets the metadata of a file and then excutes the block.

- (void)getMetadataInBackgroundWithBlock:(nullable MLBooleanResultBlock)block

Parameters

block

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

Declared In

MLPrivateFile.h

– getMetadataIncludeChildrenInBackgroundWithBlock:

Gets the metadata of a file including its children if it’s a directory and then excutes the block.

- (void)getMetadataIncludeChildrenInBackgroundWithBlock:(nullable MLBooleanResultBlock)block

Parameters

block

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

Declared In

MLPrivateFile.h

– getMetadataInBackgroundWithSkip:andLimit:block:

Gets the metadata of a file and excutes the block when done.

- (void)getMetadataInBackgroundWithSkip:(int)skip andLimit:(int)limit block:(nullable MLBooleanResultBlock)block

Parameters

skip

The number of file metadata to skip before returning any.

limit

A limit on the number of file metadata to return. The default limit is 200, with a maximum of 2000 results being returned at a time.

block

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

Declared In

MLPrivateFile.h

Get usage

+ getUsage:

Get the usage of current user.

+ (void)getUsage:(MLUsageResultBlock)block

Parameters

block

The block parameter represents usage of current user. It has 3 parameters. 1. fileCount: How many private files the current user save on MaxLeap file servers. 2. usedCapacity: The capacity current user used in bytes. 3. error: If there is an error, both fileCount and usedCapacity are -1.

Declared In

MLPrivateFile.h

Copy Private Files

– copyToPathInBackground:block:

Copys a file to another remote path.

- (void)copyToPathInBackground:(NSString *)dstPath block:(nullable MLPrivateFileResultBlock)block

Parameters

dstPath

The destination remote path.

block

Block should have the following argument signature: (MLPrivateFile newFile, NSError error)

Declared In

MLPrivateFile.h

+ copyAllInBackground:toPaths:block:

Copys a collection of private files at scrPaths to remote paths dstPaths. The result will pass in the block. The block has three parameters: isAllCompleted indicates whether all files was copied; completed contains an array of path pairs which was copied successfully, its structure: [{“from”:scrPath, “to”:dstPath}]; error is nil unless the network request failed or scrPaths does not match with dstPaths.

+ (void)copyAllInBackground:(nullable NSArray ML_GENERIC ( NSString *) *)scrPaths toPaths:(nullable NSOrderedSet ML_GENERIC ( NSString *) *)dstPaths block:(void ( ^ ) ( BOOL isAllCompleted , NSArray ML_GENERIC ( NSString *) *completed , NSError *__nullable error ))block

Parameters

scrPaths

An array of private file remote path.

dstPaths

An orderedSet of destination remote path. These paths must match with scrPaths.

block

Block should have the following argument signature: (BOOL isAllCompleted, NSArray completed, NSError error)

Declared In

MLPrivateFile.h

Move Private Files

– moveToPathInBackground:block:

Moves a file to another remote path.

- (void)moveToPathInBackground:(NSString *)dstPath block:(nullable MLBooleanResultBlock)block

Parameters

dstPath

The destination remote path.

block

Block should have the following argument signature: (MLPrivateFile newFile, NSError error)

Declared In

MLPrivateFile.h

+ moveAllInBackground:toPaths:block:

Moves a collection of private files at scrPaths to remote paths dstPaths. The result will pass in the block. The block has three parameters: isAllCompleted indicates whether all files was moved; completed contains an array of path pairs which was copied successfully, its structure: [{“from”:scrPath, “to”:dstPath}]; error is nil unless the network request failed or scrPaths does not match with dstPaths.

+ (void)moveAllInBackground:(nullable NSOrderedSet ML_GENERIC ( NSString *) *)scrPaths toPaths:(nullable NSOrderedSet ML_GENERIC ( NSString *) *)dstPaths block:(void ( ^ ) ( BOOL isAllCompleted , NSArray ML_GENERIC ( NSString *) *completed , NSError *__nullable error ))block

Parameters

scrPaths

An array of private file remote path.

dstPaths

An orderedSet of destination remote path. These paths must match with scrPaths.

block

Block should have the following argument signature: (BOOL isAllCompleted, NSArray completed, NSError error)

Declared In

MLPrivateFile.h

Create Folder

+ createFolderAtPathInBackground:block:

Create a folder at remote path file.remotePath.

+ (void)createFolderAtPathInBackground:(NSString *)path block:(nullable MLPrivateFileResultBlock)block

Parameters

path

The remote path of a directory.

block

Block should have the following argument signature: (BOOL success, NSError *error)

Declared In

MLPrivateFile.h

Share (Mock)

– shareInBackgroundWithBlock:

Share a file or directory. (Mock)

- (void)shareInBackgroundWithBlock:(nullable MLBooleanResultBlock)block

Parameters

block

Block should have the following argument signature: (BOOL success, NSError *error)

Declared In

MLPrivateFile.h