AWSUserFileManager Class Reference

Inherits from AWSContentManager : NSObject
Declared in AWSUserFileManager.h
AWSUserFileManager.m

Overview

AWSUserFileManager inherits from AWSContentManager and adds the upload capabilities.

The User File Manager uploads and downloads files from Amazon S3. It caches downloaded files locally on the device in a size-limited cache. Downloaded files may be pinned to the cache, so that they are not automatically removed when the cache size limit is exceeded. The User File Manager provides access to two folders in the Amazon S3 bucket, one called “public/” for public files, which are accessible to any user of the app, and one called “private/” which contains a sub-folder for each Amazon Cognito identified user. Files in the user’s private folder can only be accessed by that user. The User File Manager serves as the application’s interface into the file-related functionality of the User Data Storage feature. Requires the AWSS3 framework of AWSiOSSDK.

  uploadingContents

The list of currently uploading contents.

@property (nonatomic, readonly) NSArray<AWSLocalContent*> *uploadingContents

Declared In

AWSUserFileManager.h

+ defaultUserFileManager

Returns the default User File Manager singleton instance configured using the information provided in Info.plist file.

+ (instancetype)defaultUserFileManager

Discussion

Swift

let userFileManager = AWSUserFileManager.defaultUserFileManager()

Objective-C

AWSUserFileManager *userFileManager = [AWSUserFileManager defaultFileManager];

Declared In

AWSUserFileManager.h

+ registerUserFileManagerWithConfiguration:forKey:

Creates a helper client for AWSUserFileManager for specified configuration with mentioned key. Use this method only if you require a helper client with specific configuration.

+ (void)registerUserFileManagerWithConfiguration:(AWSUserFileManagerConfiguration *)userFileManagerConfiguration forKey:(NSString *)key

Parameters

userFileManagerConfiguration

AWSUserFileManagerConfiguration object for the manager.

key

A string to identify the helper client.

Discussion

For example, set the configuration in - application:didFinishLaunchingWithOptions:

Swift

 func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    let credentialProvider = AWSCognitoCredentialsProvider(regionType: .USEast1, identityPoolId: "YourIdentityPoolId")
    let configuration = AWSServiceConfiguration(region: .USWest2, credentialsProvider: credentialProvider)
    let userFileManagerConfiguration = AWSUserFileManagerConfiguration(bucketName: "myBucket", serviceConfiguration: configuration)
    AWSUserFileManager.registerUserFileManagerWithConfiguration(userFileManagerConfiguration, forKey: "USWest2BucketManager")

    return true
 }

Objective-C

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    AWSCognitoCredentialsProvider *credentialsProvider = [[AWSCognitoCredentialsProvider alloc] initWithRegionType:AWSRegionUSEast1
                                                                                                    identityPoolId:@"YourIdentityPoolId"];
    AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionUSWest2
    credentialsProvider:credentialsProvider];
    AWSUserFileManagerConfiguration *userFileManagerConfiguration = [[AWSUserFileManager alloc] initWithBucketName:@"myBucketName"
                                                                                              serviceConfiguration:configuration];
    [AWSUserFileManager registerUserFileManagerWithConfiguration:userFileManagerConfiguration 
                                                          forKey:@"USWest2BucketManager"];

    return YES;
 }

Then call the following to get the helper client:

Swift

let userFilemanager = AWSUserFileManager(forKey: "USWest2BucketManager")

Objective-C

AWSUserFileManager *userFileManager = [AWSUserFileManager userFileManagerForKey:@"USWest2BucketManager"];

Warning: After calling this method, do not modify the configuration object. It may cause unspecified behaviors.

Declared In

AWSUserFileManager.h

+ UserFileManagerForKey:NS_SWIFT_NAME:

Retrieves the helper client associated with the key. You need to call + registerUserFileManagerWithConfiguration:forKey: before invoking this method. If + registerUserFileManagerWithConfiguration:forKey: has not been called in advance or the key does not exist, this method returns nil.

+ (instancetype)UserFileManagerForKey:(NSString *)key NS_SWIFT_NAME

Parameters

key

A string to identify the helper client.

Return Value

An instance of AWSUserFileManager for specified key.

Discussion

Swift

let credentialProvider = AWSCognitoCredentialsProvider(regionType: .USEast1, identityPoolId: "YourIdentityPoolId")
let configuration = AWSServiceConfiguration(region: .USWest2, credentialsProvider: credentialProvider)
let userFileManagerConfiguration = AWSUserFileManagerConfiguration(bucketName: "myBucket", serviceConfiguration: configuration)
AWSUserFileManager.registerUserFileManagerWithConfiguration(userFileManagerConfiguration, forKey: "USWest2BucketManager")

Objective-C

AWSCognitoCredentialsProvider *credentialsProvider = [[AWSCognitoCredentialsProvider alloc] initWithRegionType:AWSRegionUSEast1
                                                                                                identityPoolId:@"YourIdentityPoolId"];
AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionUSWest2
credentialsProvider:credentialsProvider];
AWSUserFileManagerConfiguration *userFileManagerConfiguration = [[AWSUserFileManager alloc] initWithBucketName:@"myBucketName"
                                                                                          serviceConfiguration:configuration];
[AWSUserFileManager registerUserFileManagerWithConfiguration:userFileManagerConfiguration 
                                                      forKey:@"USWest2BucketManager"];

Then call the following to get the helper client:

Swift

let UserFilemanager = AWSUserFileManager.UserFileManager(forKey: “USWest2BucketManager”)

Objective-C

AWSUserFileManager *UserFileManager = [AWSUserFileManager UserFileManagerForKey:@“USWest2BucketManager”];

Declared In

AWSUserFileManager.h

+ removeUserFileManagerForKey:

Removes the helper client associated with the key and release it.

+ (void)removeUserFileManagerForKey:(NSString *)key

Parameters

key

A string to identify the helper client.

Discussion

Swift

AWSUserFileManager.removeUserFileManagerForKey("USWest2BucketManager")

Objective-C

[AWSUserFileManager removeUserFileManagerForKey:@"USWest2BucketManager"];

Warning: Before calling this method, make sure no method is running on this client.

Declared In

AWSUserFileManager.h

– localContentWithData:key:

Returns an instance of AWSLocalContent. You use this method to create an instance of AWSLocalContent to upload data to an Amazon S3 bucket with the specified key.

- (AWSLocalContent *)localContentWithData:(nullable NSData *)data key:(NSString *)key

Parameters

data

The data to be uploaded.

key

The Amazon S3 key.

Return Value

An instance of AWSLocalContent that represents data to be uploaded.

Discussion

Swift

func uploadWithData(data: NSData, forKey key: String) {

    let userFilemanager = AWSUserFileManager(forKey: "KeyUsedToRegister")
    let localContent = userFilemanager.localContentWithData(data, key: key)
    localContent.uploadWithPinOnCompletion(..., progressBlock: ..., completionHandler: ...)
}

Objective-C

- (void)uploadWithData:(NSData *)data forKey:(NSString *)key {

    AWSUserFileManager *userFileManager = [AWSUserFileManager userFileManagerForKey:@"KeyUsedToRegister"];
    AWSLocalContent *localContent = [self.manager localContentWithData:data
                                                                   key:key];
    [localContent uploadWithPinOnCompletion:...
                              progressBlock:...
                          completionHandler:...];
}

Declared In

AWSUserFileManager.h