Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong local path in LBFile.m #112

Open
skylinezy opened this issue Apr 26, 2016 · 0 comments
Open

Wrong local path in LBFile.m #112

skylinezy opened this issue Apr 26, 2016 · 0 comments

Comments

@skylinezy
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants