1

I have a request from my customer to download asset from Sitecore Content Hub programatically. I googled a lot, found examples of uploading programmatically, but no downloading.

I was thinking there must be API or SDK ready to use for downloading asset from Sitecore Content Hub via code, but no info.

Is it even possible? I found creating a public link via code and calling that endpoint as an alternative, but in my understanding, the public link is open even for anonymous users, and I do not want that.

1 Answer 1

1

If your external script user has access to the original rendition of the asset, then you can download a rendition using the WebClientSDK and the IRendition and IRenditionItem objects. IRenditionItem has DownloadAsync method:

Example code:

var asset = await client.Entities.GetAsync(8626);
var original = asset.GetRendition("downloadOriginal");
var rendition = original.Items.FirstOrDefault();

if (rendition != null)
{
    var filename = asset.GetPropertyValue<string>(Constants.Asset.FileName);
    var directory = @"C:\Users\Stylelabs\Desktop";
    var filepath = Path.Combine(directory, filename);
    await rendition.DownloadAsync(filepath);
}

For more documentation, the WebClient API docs are here: https://docs.stylelabs.com/content/3.4.x/integrations/web-sdk/index.html

Rendition download example here: https://docs.stylelabs.com/content/3.4.x/integrations/sdk-common-documentation/entity/renditions.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.