Accessing File Metadata
Every stored file is reflected as a document in the "_storage"
system table.
File metadata such as the size, content type, and checksum of a file can be
accessed from queries and
mutations via db.system.get
and
db.system.query
:
convex/images.ts
TS
import { v } from "convex/values";
import { query } from "./_generated/server";
export const getMetadata = query({
args: {
storageId: v.id("_storage"),
},
handler: async (ctx, args) => {
return await ctx.db.system.get(args.storageId);
},
});
export const listAllFiles = query({
handler: async (ctx) => {
// You can use .paginate() as well
return await ctx.db.system.query("_storage").collect();
},
});
You can check the metadata manually on your dashboard.
Accessing metadata from actions (deprecated)
Alternatively, a
storage.getMetadata()
function is available to access individual file metadata from
actions and
HTTP actions:
convex/images.ts
TS
import { v } from "convex/values";
import { action } from "./_generated/server";
export const getMetadata = action({
args: { storageId: v.id("_storage") },
handler: async (ctx, args) => {
return await ctx.storage.getMetadata(args.storageId);
},
});
Note that
storage.getMetadata()
returns a FileMetadata
, which has a
slightly different shape than the result from db.system.get
.