Publishing an asset works some times, and others don't

Hi there.
I am uploading a file, creating the asset, processing it, and publishing it, but sometimes I got version mismatch error while publishing it, randomly, sometimes it work, sometimes it won’t. I’ve read on the docs(or here in the community, can’t remember) that processing is asynchronous, so, I might be trying to publish the asset before it has done processing, but I do not have a way tok now when it has done with processing. I am using the CMA directly with typescript, no SDK. Can you guys help?

Hi @oscar.cabrera!

You’ve got the steps right:

  1. upload a file
  2. create the asset
  3. process it
  4. publish it

But in between steps 3 and 4 you should make a loop that gets the asset from the CMA and checks to see if there is a fields.file.url property. If that property doesn’t exist then the processing hasn’t finished. If it does exist then the processing has finished. You also can make sure you have the latest version of the asset so when you go to publish it you don’t get those version mismatch errors. So really the steps should be like this:

  1. upload a file
  2. create the asset
  3. process it
  4. Poll CMA for asset until fields.file["en-US"].url property exists (substitute en-US for your locale)
  5. publish it

Let us know how that works for you! Hope it helps!

hmm…, I’ll give it a try, and let you know. Thanks for your quick response!

Hi there. I am doing as you suggested, but there’s never a fields.file.url property on the response. I’m querying the CMA like this:
axios.get("https://api.contentful.com/spaces/" + space_id +"/assets/" +assetId, config)
Can you comment on this?

Ok, I can confirm that the solution works, but I had to look over the locale (“en-US”) to find the url property, so, the steps are like this:

upload a file
create the asset
process it
Poll CMA for asset until fields.file.["en-US"(or whatever the local is)].url property exists
publish it.

Hi there ,

I am doing as you suggested. but until i moved to web app and refresh the processing page version is not updated.
the steps are like this:

upload a file
create the asset
process it
(moved to CMS web app and refresh the processing page)
publish it.

I am using the CMA directly with swift language, no SDK. Can you guys help?