iPhone DropBox API: How to load a file?

后端 未结 2 1102
长情又很酷
长情又很酷 2021-02-01 10:53

A very basic question concerning dropBox integration into an iPhone app.

I followed the setup of the DropBoxSDK and everything works fine. I can log on to my account and

相关标签:
2条回答
  • 2021-02-01 11:33

    Into the DBdownload function you can skip the check by implementing the DBRestClientDelegate method loadedFile and loadFileFailedWithError

    0 讨论(0)
  • 2021-02-01 11:40

    Ok, I found this method to save my example.txt file:

    -(void) DBupload:(id)sender
    {
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
        NSString *documentsDirectory = [paths objectAtIndex:0]; // Get documents directory
        NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"Example.txt"];
    
        [self.restClient uploadFile:@"NoteBook.txt" toPath:@"/example" fromPath:filePath];
    }
    

    Turns out, no need to create a folder, dropbox will do this automatically for you if it doesn't exist.

    This is for downloading the same file form dropbox:

    -(void) DBdownload:(id)sender
    {
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
        NSString *documentsDirectory = [paths objectAtIndex:0]; // Get documents directory
        NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"Example.txt"];
        NSError *error;
    
        [self.restClient loadFile:@"/example/Example.txt" intoPath:filePath];
    
        if (filePath) { // check if file exists - if so load it:
            NSString *tempTextOut = [NSString stringWithContentsOfFile:filePath
                                                              encoding:NSUTF8StringEncoding
                                                                 error:&error];
        }
    }
    

    Hope this helps if you were struggling with a similar question.

    0 讨论(0)
提交回复
热议问题