strongloop-community / loopback-sdk-ios

iOS Client SDK for the LoopBack framework.
Other
75 stars 38 forks source link

Issue while uploading LBFile.h #45

Closed lennartstolz closed 9 years ago

lennartstolz commented 9 years ago
- (void)uploadWithSuccess:(LBFileUploadSuccessBlock)success failure:(SLFailureBlock)failure; 

This Function uses /../ModelName/prototype instead of the ../ModelName/{containerName} for uploading the file. I'm not sure if this is a bug, or I am just stupid.

hideya commented 9 years ago

Could you explain me a bit more about the issue? I'm not quite sure what those paths are. Sorry for my lack of understanding...

lennartstolz commented 9 years ago

Hey @hideya,

thanks for you reply and no worries about the lack of understanding. I know this three lines of issue were not enough to get an idea of what I'm talking about. :wink:

So I added a short code snippet to show you how I create a new LBFile-Object.

LBFileRepository *receiptFiles = [LBFileRepository repositoryWithClassName:@"Receipt"];
[receiptFiles setAdapter:self.loopbackAdapter];
NSString *imagePath = [[NSBundle mainBundle] pathForResource:@"2015-06-01-aldi" ofType:@"png"];
LBFile *file = [receiptFiles createFileWithName:@"2015-06-01-aldi.png" localPath:imagePath container:@"demo-receipts-us"];

This works like charm. When I try to upload the file with the following method:

[file uploadWithSuccess:^{
 NSLog(@"Juhu!");
} failure:^(NSError *error) {
 NSLog(@"%@", error.localizedDescription);
}];

The path property of the SLRESTAdapter.m in the method:

- (void)requestWithPath:(NSString *)path
                   verb:(NSString *)verb
             parameters:(NSDictionary *)parameters
              multipart:(BOOL)multipart
           outputStream:(NSOutputStream *)outputStream
                success:(SLSuccessBlock)success
                failure:(SLFailureBlock)failure {
// Loopback code in here ... 
}

is the following: Receipt/prototype/upload.

But for using the normal Loopback Route for POST to the API it should be: Receipt/demo-receipts-us/upload

I hope it's now a bit more understandable.

Best Lennart

hideya commented 9 years ago

Hi @lennartstolz, Thanks for the detailed explanation! Checking the code, I noticed @"Receipt" is given when creating the LBFileRepository. Is it a class you defined? As far as I know, usual way to create a file object is something like the following:

LBFileRepository *repository = (LBFileRepository*)[adapter repositoryWithClass:[LBFileRepository class]];
LBFile *file = [repository createFileWithName:fileName localPath:pathToLocalDir container:containerName];

Could you try this and see if it works for you?

lennartstolz commented 9 years ago

Thanks for your reply @hideya ,

I'll have a detailed look on this in a bit. Just tried it for a few minutes and it looks good (no errors anymore and success-block called, but the image isn't in the AWS S3 bucket.

I think I have to create a Receipt class first, because using LBFileRepository is not working with the Loopback Route /Receipt/container/upload.

hideya commented 9 years ago

You are very welcome, @lennartstolz As far as I know, LoopBack's storage service's URI format is fixed like /api/containers/:container/upload Have you checked out the following document? http://docs.strongloop.com/display/public/LB/Storage+component

lennartstolz commented 9 years ago

:+1: @hideya. Thanks for this link. I thought it would be possible to use StorageComponent as persistent storage for an model.

But this solution makes more sense.