Determining file type prior to fetching from Apiko API server

I’ve got a project using Apiko for the backend. The setup lets me grab files with a GET request to /files/:id. I can also see all file details by hitting /files. But here’s my issue: I want to know a file’s type before I actually download it. Is there a way to get just the file type for a specific ID? I’m trying to avoid unnecessary downloads and make my app more efficient. Has anyone figured out a method for this? Maybe there’s an endpoint I’m missing or a trick with the API? Any help would be great!

I encountered a similar challenge with Apiko recently. One effective approach I found was to modify the server-side code to include file type information in the response headers. This way, when you make a GET request to /files/:id, you can examine the headers without downloading the entire file. It’s a bit more work upfront, but it significantly improves efficiency in the long run. Alternatively, if you have control over the API, consider adding a new endpoint like /files/:id/metadata that returns only essential file information, including the type. This would allow you to quickly fetch file types without unnecessary data transfer.

I’ve dealt with this exact issue in a recent project. What worked for me was implementing a custom caching system on the client-side. Essentially, I stored the file metadata (including type) from the /files endpoint in local storage or IndexedDB. Then, before making any GET requests for individual files, I’d check this cache first. If the metadata wasn’t there or was outdated, I’d refresh it from the server.

This approach significantly reduced unnecessary downloads and improved overall app performance. It does require some initial setup and management of the cache, but the payoff in efficiency is worth it. Just remember to periodically sync your cache with the server to ensure you’re working with up-to-date information.

If you’re worried about storage limitations on the client-side, you could also implement a simple LRU (Least Recently Used) cache to manage the metadata more efficiently.

hey claire, have u tried using the HEAD request instead of GET? it might give u the content-type header without downloading the whole file. worth a shot imo. if that doesn’t work, maybe ask the apiko devs to add a specific endpoint for file types? good luck!