Media processing failed when creating media for product

Im doing the following mutations to create a new product and link an image to it:

1- UPLOAD IMAGE TO SHOPIFY:

using the following mutation:
mutation stagedUploadsCreate($input: [StagedUploadInput!]!) {{
stagedUploadsCreate(input: $input) {{
stagedTargets {{
resourceUrl}}}}}}
input:

img = {
“input”: {
“filename”: “cavalo.jpg”,
“httpMethod”: “POST”,
“mimeType”: “image/jpg”,
“resource”: “IMAGE”
}}
2-ASSIGN IT TO A PRODUCT:
using the following mutation:

mutation productCreateMedia($media: [CreateMediaInput!]!, $productId: ID!) {{
productCreateMedia(media: $media, productId: $productId) {{
media {{
alt
id
mediaErrors{{
code
details
message
}}
mediaWarnings{{
code
message
}}
status
}}
mediaUserErrors {{
code
field
message
}}
product {{
handle
id
}}
userErrors {{
field
message
}}
}}
}}
input:

prodImg = {
“media”: {
“alt”: “garrafa img”,
“mediaContentType”: “IMAGE”,
“originalSource”: “https://shopify-staged-uploads.storage.googleapis.com/tmp/87055565100/products/67076b1a-02ae-4240-9f19-d5b125de1b51/cavalo.jpg” (this is the url I get as a response from uploading the img)
},
“productId”: “gid://shopify/Product/9172567130412” (this id the ID i got after creating my product)
}

I get no errors as a response from productCreateMedia: (200, {‘data’: {‘productCreateMedia’: {‘media’: [{‘alt’: ‘garrafa img’, ‘id’: ‘gid://shopify/MediaImage/37661322740012’, ‘mediaErrors’: , ‘mediaWarnings’: , ‘status’: ‘UPLOADED’}], ‘mediaUserErrors’: , ‘product’: {‘handle’: ‘jaqueta-30’, ‘id’: ‘gid://shopify/Product/9172567130412’}, ‘userErrors’: }}

However, when I access the product in shopify, I get Media Processing Failed error, how to fix it?

It seems it’s a timeout error that happens “RANDOMLY” in 1/4 to 1/3 of the cases. My solution was to send the media and then use query Files to check the status (which returns the correct status of the media), if it failed, I send again until it return success. Very sad to need to make this poor solution for such problem.