Preserve url for media content after modifying the file

I would like to upload a file to Media and point an external app to the file’s url, and then I’ll need to periodically update the file externally and re-upload it. Unfortunately when I re-upload the file the url changes. Is there a way to preserve the url when I make changes to the file (or ideally, assign a canonical url to that media object that persists regardless of what I actually upload)?

You should have the external app make an Contentful Delivery API call to get the particular asset by its id, then parse out the url from the response and have the app use that. Each time you update the asset the asset’s id won’t change, but the updated file url will be different.

Alternatively, you could write a simple app to provide canonical urls which makes the api call and retrieves the current asset url then returns a 301 redirect to that url. The urls used in the external app could have all the necessary information for this middleware app to work. For example: https://canonical-url-generator.herokuapp.com/<spaceId>/<assetId>/<deliveryToken>

See https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/assets/asset for details on making an API call to get an asset.