We need to create a shared link for a file and then retrieve that link so
that we can display it inside our application.
We are able to create a shared link for a specific file (we can see it
inside Box Account on the Web) but we are not able to retrive sharedLink
via the API. It is always nil, although isShared
method returns YES.
From the header file of BoxObject.h
we find that these two methods provide
required information about shared state of the item.
@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 shared link.
[photo
isShared]
returns NO.[photo shareWithPassword:@"" message:@"" emails:[NSArray
arrayWithObject:@""] callbacks:^(id<BoxOperationCallbacks>
on1){...}];
[photo isShared]
returns YES but [photo
sharedLink] returns nilAnd if we check on the Web, we can see that file is actually shared but we cannot retrive sharedLink from the Box SDK.
Anyone has the same problem?
This is working for me, based off of 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];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With