1import { list } from "@vercel/blob";23// random order of blobs4const res = list()
It would be way easier and straight forward if the order is created_at descending, could that not be implemented either by default or via prop?
Thanks for considering this as an improvement
VercelAccepted answer
Thanks for reaching out. I don't think this is possible right now so I have shared the feedback internally. Keep them coming! :)
Vercel
Thanks for the feedback ! The ordering isn't actually random - Vercel Blob returns blobs sorted lexicographically by pathname (like dictionary order), which can appear random when filenames don't follow a predictable pattern.
Unfortunately, sorting by uploadedAt isn't possible at the storage level, so if you want that you need to work around this limitation.
Workaround: Include timestamps in your blob pathnames for chronological sorting:
12import { put } from "@vercel/blob";34// Include ISO timestamp for chronological order56const timestamp = new Date().toISOString(); // 2024-06-03T10:30:00.000Z78const blob = await put(`${timestamp}-filename.jpg`, file, { access: 'public' });9
When you list() blobs with this naming pattern, they'll automatically sort chronologically (newest first if you want reverse order, manipulate the timestamp).
Alternatively, you can sort client-side after retrieval:
12const res = await list();34const sortedBlobs = res.blobs.sort((a, b) => new Date(b.uploadedAt) - new Date(a.uploadedAt));5
Thanks!
This topic is closed. It no longer accepts new replies.