Trying to wrap my head around this one. I have a media file with an ampersand in the file name. If I try to create an Azure Media Asset, I get a BadRequest error, with this
{
error: {
code: 'InvalidDoubleEncodedRequestUri',
message:
"The request URI 'https://management.azure.com:443/subscriptions/..../resourceGroups/.../providers/Microsoft.Media/mediaServices/.../assets/M%2526G+1+Width.mp4?api-version=2018-07-01' is not valid, because it contains double encoding sequence '%25'.",
},
}
I've tried to escape the '&' in the file name, but I still get the error. What I can't figure out is that if I upload the same file via the Azure Media Service portal, it works fine. What is the portal doing that I'm not?
Update
If I do not escape the asset name, I get a 400 bad request returned instead (classic .net yellow screen of death). From what I can recall, this means the name contains invalid characters. As soon as I remove the '&', it works.
From what I've read here, it mentions that you can't use the following characters in an asset name ( '<', '>', '%', '&', ':', '\', '?', '/', '*', '+', '.', the single quote character, or any control characters). But this is confusing to me. The container name is auto generated (asset-...some guid...), and then it's just the blob within my container (which is allowed an '&' character in the file name. I just don't understand why, if I upload via the portal, it works but via the SDK fails.
Azure Portal uses the v2 API, which does not follow the Azure Resource Management naming constraints.
In the V3 API, the Asset is a named ARM entity, and thus follows the naming rules for all other Azure resources as defined here: Naming Conventions in v3
You should follow the naming guidelines for Azure ARM entities when using the v3 API. If you need to store alternate identity information, you can use the custom "AlternateId" property on the Asset. Or you can use the description property if you desire.
curl -X PUT \
'https://management.azure.com/subscriptions/XXXXXXX/resourceGroups/XXXXX/providers/Microsoft.Media/mediaServices/XXXXX/assets/myAsset?api-version=2018-07-01' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer
-H 'Connection: keep-alive' \
-H 'Content-Length: 303' \
-H 'Content-Type: application/json' \
-H 'Host: management.azure.com' \
-d '{
"properties": {
"description": "some custom description with whatever you need to store",
"alternateId": "(Optional) some custom string to help you look it up in your database"
}
}'