简体   繁体   中英

Preview of dropbox file in iOS

I am integrating dropbox with my IOS application. I am able to fetch selected file meta data. But couldn't find the way to show preview after selecting the file. Can someone suggest which API is helpful.

Drop box i am using is : https://www.dropbox.com/developers/dropins/chooser/ios

Below piece of code is called when user wants to select file from dropbox :

- (void)didPressChoose
{   
    [[DBChooser defaultChooser] openChooserForLinkType:DBChooserLinkTypePreview fromViewController:self
                                            completion:^(NSArray *results)
     {   
         if ([results count]) {
             _result = results[0];
             //After getting the result, i want to preview the file
         } else {
             _result = nil;
             [[[UIAlertView alloc] initWithTitle:@"CANCELLED" message:@"user cancelled!"
                                        delegate:nil cancelButtonTitle:@"Okay" otherButtonTitles:nil]
              show];
         }
         [[self tableView] reloadData];
     }];
}

When you ask for DBChooserLinkTypePreview , the DBChooserResult you get back from the Chooser will have an NSURL link like this:

https://www.dropbox.com/s/toyzur6e0m34t7v/dropbox-logos_dropbox-glyph-blue.png

This link type is meant for direct user interaction, so you can send a user there and Dropbox will display the page with a preview of the file if possible.

Alternatively, you may want to use DBChooserLinkTypeDirect which gives you a direct link like this:

https://dl.dropboxusercontent.com/1/view/969vkzdys770277/Testing/Images/dropbox-logos_dropbox-glyph-blue.png

This is a direct (but temporary) link to the file contents. You can download the file contents programmatically (eg, see How do I download and save a file locally on iOS using objective C? ) and then do whatever you want with it. For example, you may want to display it in an UIImageView if it's an image, etc.

Also, DBChooserResult contains a thumbnails property with links to thumbnails (if the selected file was an image or video) that might be similarly useful.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM