-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Static method or example to change asset link domains #397
Comments
Related: #193 |
It appears that this might be as simple as allowing for string replacements from SDK configuration in this file:
Such that ResolveAssetUrl function does a string substitution for the *.kc-usercontent.com URLS with a custom URL. Example: SDK Configuration:
ResolveAssetUrl would then take CustomAssetUrl and do a replace on the url: private string ResolveAssetUrl(IAsset asset)
{
var url = ReplaceAssetUrlWIthCustomAssetUrl(asset.Url);
var renditionPresetToBeApplied = Options.CurrentValue.DefaultRenditionPreset;
if (renditionPresetToBeApplied == null || asset.Renditions == null)
return url;
return asset.Renditions.TryGetValue(renditionPresetToBeApplied, out var renditionToBeApplied)
? $"{url}?{renditionToBeApplied.Query}"
: url;
}
private string ReplaceAssetUrlWIthCustomAssetUrl(url)
{
if (!string.IsNullOrEmpty(SDKConfig.CustomAssetUrl))
{
//Replace the beginning part of the asset URL such as https://assets-us-01.kc-usercontent.com or https://preview-assets-us-01.kc-usercontent.com with the SDKConfig.CustomAssetUrl
//Example above would change something like this:
//https://preview-assets-us-01.kc-usercontent.com/406ac8c6-58e8-00b3-e3c1-0c312965deb2/ba10a763-a225-41d9-86d0-16ffb31b3be3/name-change-form.pdf
//To this: https://www.somewhere.com/assets/406ac8c6-58e8-00b3-e3c1-0c312965deb2/ba10a763-a225-41d9-86d0-16ffb31b3be3/name-change-form.pdf
}
} |
hello and thanks for your submission. you're correct, since the custom asset domains are not reflected directly in API response, the implementation relies upon string replacement at the SDK/app level. your proposed approach seems viable. in practice, this would mean adjusting |
PR out there now: #398 |
Motivation
Dedicated support for custom asset domains has long been missing from this SDK.
Proposed solution
Without dedicated support customers lack guidance on best practice solutions for implementing a substitution themselves. If we had a code sample or even a static method that they could make use of it would be a big help. Not just for the custom domain use case but secure access as well, as a user has expressed interest in replacing the URL with their own endpoint, with a file handler, to make calls to our API with the needed keys.
Example:
Bet way to turn
"https://assets-us-01.kc-usercontent.com/778b7b68-e044-0006-e0eb-333eb9503651/45be1c3f-a3b9-428d-bbc6-cb3ea381405e/istockphoto-518322790-1024x1024.jpg" => "https://myassetdomain/778b7b68-e044-0006-e0eb-333eb9503651/45be1c3f-a3b9-428d-bbc6-cb3ea381405e/istockphoto-518322790-1024x1024.jpg"
Additional context
Issue (#381)
Issue (#311)
The text was updated successfully, but these errors were encountered: