MongocampBucketFiles
A dedicated file browser for one GridFS bucket: paginated, filterable, sortable table of the bucket's files (with clean FileInformation data — filename, size, upload date, metadata — no extended-JSON unwrapping needed), plus upload, download, delete, and rename/edit-metadata actions.
This is a second, purpose-built way to browse a bucket's files, alongside MongocampCollectionData's existing generic raw-document view of the <bucket>.files/<bucket>.chunks collections — that view is unchanged and still works; this component adds a cleaner, action-rich alternative scoped to a single bucket.
Usage
<script setup>
const route = useRoute()
const bucketName = route.params.bucket_name
</script>
<template>
<MongocampBucketFiles :bucket-name="bucketName" />
</template>Typically reached via MongocampCollections's "Browse files" action on a bucket row (its bucketFilesPath prop, default /secured/admin/buckets) — the module doesn't own routing itself, so you provide the page that renders this component for a given bucket_name route param, matching the same pattern MongocampRoles' grantsPath uses for role grants.
Props
| Prop | Type | Description |
|---|---|---|
bucketName | string | The GridFS bucket to browse (no .files/.chunks suffix — the bare bucket name) |
hideRefresh | boolean | Hide the component's own reload button, e.g. when the page calls the exposed refresh() from its own header. Default false. |
thumbnailPreset | string | Server 2.11: an image preset of the declared bucket (variants.presets, e.g. thumb) — adds a thumbnail column for image files (asked once each, as blob URLs, freed on page change). Without sharp on the server (501) or for an unknown preset (400) the column goes away with a one-line note and nothing more is asked. |
previewPreset | string | Server 2.11: the preset the preview asks for images (falls back to the original). |
collectionsPath | string | Where a referencing collection's data page lives (the Referenced by links); falls back to the module option paths.collections. |
Signed links (server 2.11)
A row's Share link opens a dialog: choose how long the link stays valid (15 minutes, 1 hour, 1 day, 7 days — the server's maximum FILE_LINK_MAX_DURATION is 7 days by default; a longer one is refused with its reason), Create link, copy it. The link downloads the file without signing in until it expires (410) or the bucket's links are revoked (403). Revoke all links (toolbar) is confirmed by typing the bucket's name. In proxy mode the link goes through this app's proxy route — see Server proxy auth.
Declared buckets (server 2.11)
A bucket declared on the server (defineMongocampBucket) gets a Declared bucket badge, and the file references of declared collections that point here are listed as Referenced by links (collection.field → that collection's data page). The delete dialog then warns that documents may refer to the file. The server does not tell the allowed types or image variants, so the file picker is not narrowed; an upload of a refused type (checked by content, 415) is listed with "The bucket only accepts these types of file: …". The information comes from useMongocampFiles().getBucketInfo (utils/bucketInfo.ts bucketDeclarationOf); a failure just leaves the line out.
In a page with its own header
The component can hand its toolbar to the page around it:
refresh()is exposed — call it through a template ref from your own reload button, and sethideRefreshto drop the built-in one.toolbarslot — your own buttons, placed beside the built-in ones.changedevent — emitted after a file was uploaded, renamed or deleted, once the component has reloaded. Never on a failed or cancelled action, never on a plain reload.
<script setup lang="ts">
const list = useTemplateRef<{ refresh: () => void }>('list')
</script>
<template>
<header>
<h1>My title</h1>
<UButton icon="i-lucide-refresh-cw" @click="list?.refresh()" />
</header>
<MongocampBucketFiles ref="list" :bucket-name="name" hide-refresh @changed="reloadOtherLists">
<template #toolbar>
<UButton>Mine</UButton>
</template>
</MongocampBucketFiles>
</template>Columns
| Column | Description |
|---|---|
| Filename | Sortable |
| Size | Sortable by the underlying byte length; displayed human-readable (B/KB/MB/GB/TB) |
| Uploaded | Sortable by uploadDate; displayed via toLocaleString() |
| Metadata | A "N keys" button opening a read-only JSON view when the file has metadata, — otherwise |
| — | Download / rename / delete action buttons |
Filtering, sorting, pagination
The filter input searches filename (debounced, case-insensitive): server 2.6 searches files with Lucene in the body of POST …/files/search, so the term is sent as filename:*term* (Lucene characters escaped) with filterCaseInsensitive — no URL length limit. Sorting and pagination both refetch through useMongocampFiles's listFiles, which reads the total row count from the x-pagination-count-rows response header. Under PAGING_MAX_ROWS (2.6 caps file lists too) the list pages with the size the server used and says so (data-test="row-cap-note"). An upload larger than the server's GRIDFS_UPLOAD_MAX_BYTES (useMongocampLimits) is listed as failed without being sent.
Actions
- Download — reuses
useMongocampFiles'sdownloadFile, tracked viadownloadingFileIds - Preview — opens
MongocampFilePreviewin a drawer - Rename / edit metadata — a dialog with the filename and the metadata as one JSON text (must be a single JSON object, empty = none; invalid text shows an error and disables Save), saved via
updateFileInformation. Nested values are kept as typed - Delete — behind a confirmation modal, calls
deleteFile; a file that is already gone counts as deleted and the list reloads - Upload — toolbar button (several files at once) or drag and drop files onto the component. Files go up one after the other via
uploadFiles; progress ("Uploading 2 of 5") and a summary with the failed files (name and server message) are shown, a failure never stops the rest, and the table reloads when anything was uploaded
Download, rename and delete are tracked via useMongocampFiles's own loading-state refs (downloadingFileIds, fileActionInFlight, uploading) and show success/error toasts from the composable itself — the component doesn't duplicate that feedback.
Related
useMongocampFiles—listFiles/deleteFile/updateFileInformation/downloadFile/uploadFileMongocampCollections— thebucketFilesPath-linked entry pointMongocampCollectionData— the generic raw-document view that still covers<bucket>.files/<bucket>.chunkscollections directly
Distribution of the stored files
A collapsed Distribution of the stored files section charts one field of the bucket's <bucket>.files collection (MongocampCollectionCharts): by default the contentType (or metadata.contentType), else the uploadDate (documents per month), else the first field with something to count; the field select offers text, number, date and boolean fields (useMongocampFieldTypes). Nothing is requested until the section is opened. It is hidden for a user who may not read <bucket>.files (the server's answer from GET /auth/permissions; the profile's grants until it arrives), and says so when no field can be charted.