IOS BoxSDK returns zero for sharedLink

We need to create a common link for the file, and then restore this link so that we can display it inside our application. We can create a shared link for a specific file (we can see this inside the Box account on the Internet), but we cannot get sharedLink through the API. It is always zero, although the isShared method returns YES.

From the BoxObject.h header BoxObject.h we find that these two methods provide the required information about the general state of the element.

 @protocol BoxObject // ... // Information about the shared state of the item @property (readonly, getter = isShared) BOOL shared; @property (readonly) NSString *sharedLink; //... @end 

This is how we create a shared link.

  • To find the BoxFile that we would like to provide allows us to call this object photo. The previous call method shareWithPassword: message: emails: callbacks :, [photo isShared] returns NO.
  • call [photo shareWithPassword:@"" message:@"" emails:[NSArray arrayWithObject:@""] callbacks:^(id<BoxOperationCallbacks> on1){...}];
  • inside on1.after we check if the answer == BoxCallbackResponseSuccessful and then we call [photo updateWithCallbacks: ^ (id on2) {..}]
  • inside on2.after we check if the answer == BoxCallbackResponseSuccessful
  • upon successful response, [photo isShared] returns YES, but [photo sharedLink] returns nil

And if we check on the Internet, we will see that the file is actually split, but we cannot extract sharedLink from the Box SDK.

Does anyone have the same problem?

+8
ios box api
source share
3 answers

This works for me based on the code already posted and the information found on github here

 - (void) getShareableLinkForFileId:(NSString *)fileId { BoxFileBlock fileSuccess = ^(BoxFile *file) { NSDictionary *fileInfo = file.rawResponseJSON; if (![fileInfo[@"shared_link"] isEqual:[NSNull null]]) { NSDictionary *linkData = fileInfo[@"shared_link"]; //Do something with the link } else { // failure } }; BoxAPIJSONFailureBlock failure = ^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, NSDictionary *JSONDictionary) { //Handle the failure }; BoxFilesRequestBuilder *builder = [[BoxFilesRequestBuilder alloc] init]; BoxSharedObjectBuilder *sharedBuilder = [[BoxSharedObjectBuilder alloc] init]; sharedBuilder.access = BoxAPISharedObjectAccessOpen; builder.sharedLink = sharedBuilder; [[BoxSDK sharedSDK].filesManager editFileWithID:fileId requestBuilder:builder success:fileSuccess failure:failure]; } 
+1
source share

I managed to get a link to the share by updating the folder myself. This is the code I came up with:

 [boxFile shareWithPassword:@"" message:@"" emails:@[ @"" ] callbacks:^(id<BoxOperationCallbacks> on) { on.after(^(BoxCallbackResponse response) { if (response == BoxCallbackResponseSuccessful) { [self.rootFolder updateWithCallbacks:^(id<BoxOperationCallbacks> on) { on.after(^(BoxCallbackResponse response) { BoxFile *updatedBoxFile = (BoxFile*)[self.rootFolder.children objectAtIndex:self.selectedIndexPath.row]; NSString *fileName = updatedBoxFile.name; NSString *shareLink = updatedBoxFile.sharedLink; NSLog(@"%@ [%@]: %@", fileName, updatedBoxFile.isShared ? @"YES" : @"NO", shareLink); }); }]; } else { [BoxErrorHandler presentErrorAlertViewForResponse:response]; } }); }]; 

This is with the old API v1. Not sure if it has changed with the new v2.

0
source share

You can create a shared link by editing its information using Box V2:

  Box2FolderBlock folderSuccess = ^(Box2Folder *folder) { if (![[folder sharedLink] isEqual:[NSNull null]]) { NSString *sharedUrl = [[folder sharedLink] objectForKey:Box2APIObjectKeyURL]; } else { // failure } }; Box2FileBlock fileSuccess = ^(Box2File *file) { if (![[file sharedLink] isEqual:[NSNull null]]) { NSString *sharedUrl = [[file sharedLink] objectForKey:Box2APIObjectKeyURL]; } else { // failure } }; Box2APIJSONFailureBlock failure = ^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, NSDictionary *JSONDictionary) { }; BoxSharedObjectBuilder *sharedLinkObject = [[BoxSharedObjectBuilder alloc] init]; sharedLinkObject.access = BoxAPISharedObjectAccessOpen; BoxAPIJSONOperation *operation; if (isFile == NO) { sharedLinkObject.canPreview = BoxAPISharedObjectPermissionStateEnabled; BoxFoldersRequestBuilder *requestBuilder = [[BoxFoldersRequestBuilder alloc] init]; requestBuilder.sharedLink = sharedLinkObject; operation = [boxSDK.foldersManager editFolderWithID:fileOrFolderId requestBuilder:requestBuilder success:folderSuccess failure:failure]; } else { sharedLinkObject.canDownload = BoxAPISharedObjectPermissionStateEnabled; BoxFilesRequestBuilder *requestBuilder = [[BoxFilesRequestBuilder alloc] init]; requestBuilder.sharedLink = sharedLinkObject; operation = [boxSDK.filesManager editFileWithID:fileOrFolderId requestBuilder:requestBuilder success:fileSuccess failure:failure]; } 
0
source share

All Articles