Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
THRUST SERVICES & TOOLS
CLOUD EDITIONS
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Web CMS (TeamSite)
Bug in GetAssetMetadataItem?
Sky_Rumsey
Hi,
Continuing with my programming against the Mediabin WebService API, I seem to have come across what appears to be a *bug* using the method GetAssetMetadataItem.
My colleague added an extra MetaData item for our images, which I now need to automatically update (30,000 or thereabouts!). The new MBItem is an int type (represents the primary key value in our main database)
However, whilst testing (in a dev environment, which has latest sp 4.5.3), it seems that unless the item has the metadata already populated, calling GetAssetMetadataItem causes a 500 internal server error on the mediabin server. There seems to be no evidence of any errors logged (in event viewer or ..\MediaBin Server\Logs\ directory.
The API clearly states that if the metadata or asset is missing, the function will return null, and not error!
A very simple example of the calling / erroring code is given below:
private void getAssetsForContainer(string containerID)
{
string[] assetIDs = mbs.GetAssetIDList(containerID);
MBMetadata data = null;
foreach (string assetID in assetIDs)
{
// use the hardcoded GUID for the new metadata item
// ( I have verified this a few times - definitely correct!)
data = mbs.GetAssetMetadataItem(assetID, "{4B0C30C6-CAAB-42DA-B131-E01EB6A82291}");
// the display the data for debugging
parseMetaData(data);
}
}
Again, if there's anything I seem to be doing wrong of have overlooked, can someone please let me know.
Kind Regards
Sky Rumsey
Brandbank
Find more posts tagged with
Comments
Konidala
I don't think it's a bug. It works on my system. I would recommend to use 'ReviseAssetMetadata' if you want to update the assets metadata. Thanks
Sky_Rumsey
Hi,
Thanks for the reply, however, since the code doesn't perform on our server as mentioned in the API, in that it errors (and there really is little done client side), I am still cautious about it. Did you test it against an Asset that does not have the Metadata attached to it? The steps we took to arrive at this point is simply, create a new metadata item (of type int) on the Mediabin server, and try and get that metadataitem for an asset by the Webservice API. This is when the errors occurrs. Browsing to the MediaBinServer.asmx page and directly accessing the method through IE will also error, removing any client code problems
)
The ReviseAssetMetaData, as you suggested, should achieve the desired outcome e.g. just add / revise the ID, which would be the next call in the code if the GetAssetMetaDataItem returned null. By skipping the GetAssetMetaDataItem , I am unable to audit the data e.g. a count of non-updated assets, and whilst this is not of importance to me right now, I can envision a time when it will be.
Again, thanks for taking the time to reply.
Regards
Sky Rumsey
msnider
There is a misprint in the API doc. If an asset does not currently contain the requested metadata item then the following exception is thrown:
MBException: The requested metadata item is unavailable. (0x80040500)
Placing a try\catch around your code should allow you to test if the asset has that particular metadata.
I will see that the doc is corrected.
Mark
Sky_Rumsey
Hi Mark,
Thanks for the reply. Sadly, placing a try/catch block when this call is in a loop of 30,000 items would seriously decrease performance.
Surely it should return null if no metadata, and if there is a metadata with a null value (though I have been told this is not allowed by my colleague who administers mediabin), then that should be realised by reviewing the metadata itself?
Is this something that is likely to remain? If so, when would the call return null? It would seem never, and throws an exception instead!
What is the recommended way of update / insert a metadata item using the webservices API? If Revise is used, is there a way to tell whether it was added or updated? And if the Get throws an error meaning it must be inserted using Revise, is there then not a optimization opportunity here for next release?
Regards
Sky Rumsey
msnider
Unfortunately, because there are many ways that GetAssetMetadataItem could fail....some examples are: invalid asset id, invalid metadata id, user does not have access to asset, user does not have access to metadata, and ( in your case ) asset does not have metadata....returning just null is not sufficient. Therefore, the only way to return specific error information is by throwing an exception especially since most client apps would probably handle these various error conditions differently.
In looking at your use case, why are you checking to see if it has the metadata item....the ReviseAssetMetadata call will either add the metadata if it doesn't already exist or it will update the current value if it does. Also, it seems like you just want to blast an update to all 30,000 assets all of which probably won't have the item anyways ( since the metadata item was just newly created). In this case, you might want to use ReviseAssetMetadata_Bulk....it will bulk update all 30,000 assets in one web service call.
Mark
Sky_Rumsey
Thanks Mark for giving a little bit more insight here.
And yes, I am wanting to 'blast' the assets with an update. I will experiment with the bulk update as you suggested.
btw, just implemented a simple workflow to search mediabin for multiple images and retrieve based on user's selected criteria and found it to be very efficient for our purposes. Think it will save our imaging team lots of time!
Regards
Sky
Konidala
I think 'ReviseAssetMetadata_Bulk' will update the same metadata value for all the assets. Incase if you have different metadata values for the assets then need to use 'ReviseAssetMetadata' API. Thanks
Sky_Rumsey
Hi all,
I am using ReviseAssetMetadata as Kondiala had suggested I would need ( it's varying values for each asset so bulk was of no use in this instance), and in doing so I noticed that using GetAssetMetadataItems(string assetID, MBMetadata[] metadataIDs) with an array of just one (btw, the API documenation for this method is wrong as well!)
e.g.
string[] metadataIDs = new string[] { "{4B0C30C6-CAAB-42DA-B131-E01EB6A82291}" };
doesn't error, but returns an empty Metadata array, unlike the single call GetAssetMetadataItem(string assetID, string metadataID). This avoids the problem of the expensive try / catch calls, though there is an assumption that other problems have not caused this to return an empty array.
This is a more of a follow-up to my original post in case anyone wants that functionality. I am currently passing in 2 metadataIds in the GetAssetMetadataItems method, and it either returns me and array of 1 or 2 in length depending on whether the asset has the ID field that I am updating.
Not sure how useful this information is in general, but it offers a workaround to my original problem. I believe these subtle differences will be clearer in the amended API documentation [see previous replies].
I would like to say that I've found 3 misprints so far in the API guide within the last week. Is this documentation up for review soon as such indescrepancies can be costly in time and effort when debugging code.
Regards
Sky Rumsey
Brandbank Ltd
lyman
We apologize for the inconvenience and yes the documentation is under review. In the meantime I hope you feel you came to the right place.
Cheers,
Lyman Hurd