3

We recently upgraded our Content Hub development instance to the latest versionless version. While testing one of the integrations, we encountered an issue that I'd like to explain.

We are attempting to upload and create an asset from a local file using the WebClient SDK (latest version). Below is the code we are using:

var uploadSource = new LocalUploadSource("C:\\my-image.jpg", "my-image.jpg");

var request = new UploadRequest(uploadSource, "AssetUploadConfiguration", "NewAsset");

// Initiate upload and wait for its completion.
var response = await client.Uploads.UploadAsync(request).ConfigureAwait(false);

// Extract the ID of the newly created asset from the location header.
var responseId = await client.LinkHelper.IdFromEntityAsync(response.Headers.Location).ConfigureAwait(false);

This code is referenced in the Sitecore documentation. It was functioning correctly before the upgrade. However, after the upgrade, we encountered an error in the following line of code:

client.LinkHelper.IdFromEntityAsync(response.Headers.Location).ConfigureAwait(false);

The error message is as follows:

at Stylelabs.M.Sdk.WebClient.Http.TemplateExtensions.GetVariableValue(Uri uri, Link template, String variable)
   at Stylelabs.M.Sdk.WebClient.Http.TemplateExtensions.GetVariableValue(Link link, Link template, String variable)
   at Stylelabs.M.Sdk.WebClient.Clients.LinkHelper.<GetVariableValueAsync>d__40.MoveNext()

I have tested this code on the old version (4.0), and it is working fine there. Anyone have any insights on this issue?

2 Answers 2

3

This issue is occuring because the version gets appended in the url(?version=2.0), when reading response in the location header through the UploadAsync method. You can change the above code to as below.

// Initiate upload and wait for its completion.
var response = await client.Uploads.UploadAsync(request).ConfigureAwait(false);
if(response!=null){
// fetch the asset url without query params
string url = $"{response.Headers.Location.Scheme}://{response.Headers.Location.Host}{response.Headers.Location.AbsolutePath}";
// Extract the ID of the newly created asset from the location header.
var responseId = await client.LinkHelper.IdFromEntityAsync(url).ConfigureAwait(false);
}

Hope this helps!!!

2

I have raised this ticket with Sitecore support, and they acknowledged it as a bug and created a ticket MONE-44641 with high priority. Meanwhile, they suggested a workaround similar to the one mentioned by Chirag in the initial response:

"The issue has been identified to be specific to the inclusion of 'version=2.0' in the URL. Avoiding the version in the URL may serve as a potential workaround."

They mentioned that this issue will be fixed in the next release.

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.