Skip to content

Wrong local path in LBFile.m #112

@skylinezy

Description

@skylinezy

I found this issue when debugging my file uploading code. I have a jpg file in the app bundle and has no problem to get the file path using:
[[NSBundle mainBundle] pathForResource:@"testImage" ofType:@"jpg"];

But when I call the uploadWithSuccess:failure on my subclass of LBFile object which created as:

ImagesRepository *repository = [ImagesRepository repository];
repository.adapter = self.adapter;

LBFile *file = [repository createFileWithName:name   // "testImage.jpg"
                                    localPath:path   // the path got using NSBundle
                                    container:@"aContainer"];

the fullLocalPath seems to be wrong. the path returned by NSBundle already included the file name but in the following code the fullLocalPath is assembled with an additional file name at the end. Thus it ends as something like some/path/testImage.jpg/testImage.jpg and NSDictionary *attributes = [[NSFileManager defaultManager] attributesOfItemAtPath:fullLocalPath error:&error]; returns nil.

- (void)uploadWithSuccess:(LBFileUploadSuccessBlock)success
                  failure:(SLFailureBlock)failure {

    NSString *fullLocalPath = [self.localPath stringByAppendingPathComponent:self.name];
    NSInputStream *inputStream = [NSInputStream inputStreamWithFileAtPath:fullLocalPath];
    NSString *mimeType = mimeTypeForFileName(self.name);
    NSDictionary *attributes = [[NSFileManager defaultManager] attributesOfItemAtPath:fullLocalPath
                                                                                error:NULL];
    NSInteger length = attributes.fileSize;
...
}

I fixed this issue in my project by replacing
NSString *fullLocalPath = [self.localPath stringByAppendingPathComponent:self.name];
with
NSString *fullLocalPath = self.localPath;
in above code snippet and it is working in my case. Should it be an official fix? Has anyone encountered this problem before?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions