Retrieving the sharedLink URL for the uploaded file via the logged in app user?

Highlighted
Occasional Contributor

Retrieving the sharedLink URL for the uploaded file via the logged in app user?

The following code is being used to upload a file to a folder in Box and that part is working successfully.  Upon successful completion of the upload, the file object is not returning the sharedLink.URL for the file though (current example shows that value being logged to the debug window in the first NSLog statement that is in larger font than others).  So a BoxFileRequest is made to retrieve information about that file but it too returns a nil value in the sharedLink.url property.  So how are we supposed to actually retrieve the sharedLink URL for the uploaded file via the logged in app user?
 
    @try{
      if((self.report.mediaType == VIDEO) || (self.report.mediaType ==IMAGE)){
        NSURL *url = [NSURL URLWithString:self.report.mediaURLString];
        NSData* data = [NSData dataWithContentsOfURL: url];
        BOXFileUploadRequest *uploadRequest = [self.syncher.clientfileUploadRequestToFolderWithID:self.boxSourceFilesFolderID
                                                                                          fromData:data
                                                                                          fileName:self.report.visualMediaFileName];
        [uploadRequest performRequestWithProgress:^(long longtotalBytesTransferred, long long totalBytesExpectedToTransfer) {
        } completion:^(BOXFile *file, NSError *error) {
          NSLog(@"file info url: %@", [file.sharedLink.urlabsoluteString]);

          BOXFileRequest *fileInfoRequest = [self.syncher.clientfileInfoRequestWithID:file.modelID];

          [fileInfoRequest performRequestWithCompletion:^(BOXFile*file, NSError *error) {
            NSLog(@"file info url: %@", [file.sharedLink.url absoluteString]);
            self.returnBoxVideoURLString = [file.sharedLink.urlabsoluteString];
            [self generatePDF];
          }];
        }];
      }  // end if

    

 
    }@catch (NSException *ex){

      

    }
1 REPLY 1
Highlighted
Box Employee

Re: Retrieving the sharedLink URL for the uploaded file via the logged in app user?

After uploading the file, you would have to make an API call to create a shared link for that file. In the response to this API call, you will get the shared link for the file.

 

Here's the documentation for the Create Shared Link endpoint.

 

Here's sample code showing how to call the Create Shared Link endpoint using the Box iOS SDK.

 

 

BOXContentClient *contentClient = [BOXContentClient defaultClient];
BOXFileShareRequest *shareRequest = [contentClient sharedLinkCreateRequestForFileWithID:@"file-id"];

// Optional: Customize the shared link to be created
shareRequest.accessLevel = BOXSharedLinkAccessLevelCompany;
shareRequest.expirationDate = [NSDate dateWithTimeInterval:3600 sinceDate:[NSDate date]];
shareRequest.canDownload = NO;
shareRequest.canPreview = YES;

[shareRequest performRequestWithCompletion:^(BOXFile *file, NSError *error) {
    // You can confirm creation of the shared link through the sharedLink 
    // property of the BOXFile that is returned.
    NSLog(@"Shared link URL: %@", file.sharedLink.url);
}];