Skip to main content
Solved

BoxItem createSharedLink


ben halfon

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
 

 

 

Best answer by Jey Bueno Box

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! 😉

View original
Did this topic help you find an answer to your question?

3 replies

Jey Bueno Box
  • Community Manager
  • 315 replies
  • Answer
  • August 29, 2024

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! 😉


ben halfon
  • Author
  • New Participant
  • 3 replies
  • September 3, 2024

Thank you for your help :)


Jey Bueno Box
  • Community Manager
  • 315 replies
  • September 3, 2024

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


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings