Skip to main content

I have upgraded my box SDK version (2.32.0 → 4.11.1)
In 2.32.0 there is a way to create shared link to BoxItem object:

private String createSharedPath(BoxItem item) {

if (Objects.isNull(item)) return null;



BoxSharedLink.Permissions permissions = new BoxSharedLink.Permissions();

permissions.setCanDownload(true);

permissions.setCanPreview(false);



BoxSharedLink sharedLink = item.createSharedLink(BoxSharedLink.Access.COMPANY, null, permissions);



return sharedLink.getDownloadURL();

}

In 4.11.1 BoxItem does not include createSharedLink function.
How can I perform the same thing in the new version? 

I could not found anything familiar in the docs
 

 

 

Hi @ben halfon 👋

Great to know you have upgraded your Box SDK version. You may refer to the updated code snippet to help you achieve the same functionality of creating a shared link to a `BoxItem` in the newer version of the SDK (4.11.1):
 

```java

private String createSharedPath(BoxItem item) {

if (Objects.isNull(item)) return null;

 

BoxSharedLink.Permissions permissions = new BoxSharedLink.Permissions();

permissions.setCanDownload(true);

permissions.setCanPreview(false);

 

BoxSharedLink.Info sharedLinkInfo = BoxSharedLink.createDefaultInfo();

sharedLinkInfo.setAccess(BoxSharedLink.Access.COMPANY);

sharedLinkInfo.setPermissions(permissions);

 

BoxFile file = (BoxFile)item; // Assuming item is a file, adjust accordingly for folders

 

try {

BoxSharedLink.createSharedLink(file.getResource(), sharedLinkInfo);

return file.getInfo().getSharedLink().getDownloadURL();

 

} catch (BoxAPIException e) {

System.out.println("Error creating shared link: " + e.getMessage());

return null;

}

}

```

Looking forward for best results! 😉


Thank you for your help :)


My pleasure! Feel free to post your topics/questions related to Box in our community. 🤗


Reply