How to change save as asset name?

Iā€™ve calculus-summary1-1.pdf asset, and I want save as name to be calculus-summary1-1.pdf instead of 1595023185-calculus-summary1-1.pdf, Iā€™m not sure where 1595023185 is coming from may be itā€™s the id of the asset.

Here is the full url,
https://www.datocms-assets.com/25569/1595023185-calculus-summary1-1.pdf

How to get only the asset name when save as clicked.

unfortunately @henok.tesfaye we prepend all the assets with a timestamp. We cannot remove that, sorry!

Got it, thank you @mat_jack1. Is there any other workaround for this?

Unless you do something on top of us, no, sorry :frowning:

A suggestion / feature request regarding thisā€¦

There are many scenarios where an application would like to construct a URL to an asset based on a known pattern, i.e. no CMS API request required to determine the assetā€™s URL. If we have a list of 100 items on a page (that come from somewhere other than the CMS) and each needs an image, we donā€™t want to have to make a CMS API request for that specific 100 items to determine their URLs.

Iā€™m not sure how many application features weā€™ve developed where we rely on this, but itā€™s at least double digits.

It would be ideal if we could specify the URL to the asset or, alternatively, specify a secondary valid external URL where we could follow our pattern.

Thank you.

1 Like

Hello @donnie.hale and welcome to Community :slight_smile:

Would you be able to provide an example to help me understand better your use case?

Wouldnā€™t be possible for you to fetch all the assets that you have tagged somehow with one API call, for example?

The secondary URL could be managed with a model in the CMS where you have a string field which represents the slug and an asset field with the final asset. But this will require one API call to retrieve the asset URL. It can be done with a lambda function, and itā€™s also the recommended way to have stable assets URL, if you need to change an asset and retain the same URL.

(Sorry for the delay in replyingā€¦)

As I mentioned, weā€™ve had this scenario come up multiple times in another application where weā€™re using a different CMS vendor which allows us to directly control the path and URL of assets. In other words, we donā€™t have to attach an asset to a content item and use a content request to retrieve the assetā€™s URL.

Hereā€™s the typical scenario: Thereā€™s another system, e.g. a CRM or inventory system, whose content and structure we donā€™t control. So we canā€™t add asset URLs to the items in that system. Each item has a unique ID. Weā€™re developing an application which allows users to interact with those items: view, page, filter, etc. Say the users are viewing 50 items at a time out of 2,500 total items.

Because of the sorting, filtering, and paging capabilities, the set of unique item IDs displayed at any time are not contiguous nor are they predictable.

In the application weā€™re developing, we want to associate an asset with each item - an image, a pdf file, whatever.

If we can directly control the URL of these assets in the CMS, then we can know that each itemā€™s asset URL is of the form: https://{tenant-domain-name/assets/crm-items/{unique-item-id}.png. Our application can simply construct URLs of that form just by knowing each item ID.

As things stand with DatoCMS now, weā€™d first have to define a content model to represent each item. Then weā€™d have to create 2,500 content items of that model. That in itself is a significant amount of overhead. But then, worse than that, at runtime of our application, weā€™d have to construct a query thatā€™s essentially: ā€œWHERE unique-item-id IN (list,of,50,item,ids)ā€, process each content item returned in the response to that query, and then pull the asset URL out of each.

Hopefully that makes sense. As I said, weā€™ve followed the above pattern of ā€œconstruct the asset URL b/c we know the convention of the asset URL formatā€ in several features of another application.

I really appreciate you asking me the follow-up question.

Donnie Hale

Thank you @donnie.hale I understand now.

Unfortunately since the filename cannot be set, you will always need to do at least one API call to get the upload objects, from which you can get the asset URL.

But, you can filter by filename and if you have simple letter-only string that you can use for your filename, that will be present in the final URL. So you can use that to find the asset and get the URL.

I know that you need one extra API call, but maybe if you have only 2500 items you could do it once at build time and store all the upload URLs so that then you have the mapping locally and you can skip the API call when you only need the URL?

What do you think?

Thanks again for the reply.

I understand that there are workarounds and optimizations that can be made in view of whatā€™s currently possible.

You said, ā€œsince the filename cannot be set.ā€

The argument Iā€™m making is that it would a valuable enhancement to DatoCMS to allow the filename/URL to be set to a known value at the time the asset is uploaded.

-Donnie

Yep, I see.

I think this is the closest feature request that we have at the moment: When replacing asset keep same url

If you want to upvote and add a comment there it will surely be helpful and give a bit more priority to that. I cannot promise anything, but weā€™ll surely review it when evaluating new features to implement.

Thank you!