Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

nil value reading plist file from document folder after download from Amazon S3 #56

Closed
gazolla opened this issue Oct 24, 2014 · 1 comment

Comments

@gazolla
Copy link

gazolla commented Oct 24, 2014

I created an app that download a plist file from Amazon S3.

-(void) getFile:(NSString *)fileName{
    self.s3Manager = [[AFAmazonS3Manager alloc] initWithAccessKeyID:@"..." secret:@"..."];
    self.s3Manager.requestSerializer.region = AFAmazonS3SAEast1Region;
    self.s3Manager.requestSerializer.bucket = @"verba";

    NSString* documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
    documentsPath = [documentsPath stringByAppendingPathComponent:fileName];

    NSOutputStream *stream = [[NSOutputStream alloc] initToFileAtPath:documentsPath append:NO];

    [self.s3Manager getObjectWithPath:@""
                         outputStream:stream
                             progress:^(NSUInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead) {
         NSLog(@"%f%% Downloaded", (totalBytesRead / (totalBytesExpectedToRead * 1.0f) * 100));
    } success:^(id responseObject) {
         NSLog(@"Download Complete");
    } failure:^(NSError *error) {
        NSLog(@"Error: %@", error);
    }];
}

Then I checked if the plist file was in document folder. And it was. So I tried to open plist file and the result was nil:

-(NSString*) loadListName:(NSString*)fileName{
    NSString* documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
    NSString* filePath = [documentsPath stringByAppendingPathComponent:fileName];

    NSDictionary *temp;
    if ([[NSFileManager defaultManager] fileExistsAtPath: filePath]){
        temp = [NSDictionary dictionaryWithContentsOfFile:filePath];
    } else {
        NSLog(@"File not found.");
    }

    NSString *listName = [temp objectForKey:@"name"];

    return listName;
}

So I tried to add plist file manually. I downloaded and copied it to the documents folder and then dictionaryWithContentsOfFile could open the file. So I suppose that plist file was corrupted when I download the file using AFAmazonS3Client.

What I am doing wrong ?

@mattt
Copy link
Contributor

mattt commented Nov 29, 2014

Sorry, but I could not reproduce this. If you're still having trouble, please open a new issue with a small example that reproduces this issue, or try asking over on Stack Overflow.

@mattt mattt closed this as completed Nov 29, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants