pingdotgg / uploadthing

File uploads for modern web devs
https://uploadthing.com
MIT License
3.74k stars 267 forks source link

feat: UTApi - getFileUrls should return the customId #804

Closed Thiago-cpu closed 2 months ago

Thiago-cpu commented 2 months ago

Describe the feature you'd like to request

When I retrieve a list of urls using the customIds, i receive a list with key and url, I don't have an easy way to say which customId belongs to the url retrieved.

Describe the solution you'd like to see

const customIds = [...]
const images = await utapi
      .getFileUrls(customIds, {keyType: "customId"})
      .then((r) => new Map(r.data.map(d => ([d.customId, d.url])))); // currently we just have key and url,

Additional information

No response

๐Ÿ‘จโ€๐Ÿ‘งโ€๐Ÿ‘ฆ Contributing

markflorkowski commented 2 months ago

We're actually considering deprecating the getFileUrls() helper, as it is a bit of an anti-pattern, and we now support URLs scoped to your app with utfs.io.

With the recent change, you can now also use your own customIds directly in the URL without having to make an API call to get the filekey for the url.

Valid URL patterns are:

https://utfs.io/f/FILE_KEY <-- how it's always been https://utfs.io/a/APP_ID/FILE_KEY https://utfs.io/a/APP_ID/CUSTOM_ID