Files
DiscordClone/convex/files.ts

21 lines
550 B
TypeScript

import { mutation, query } from "./_generated/server";
import { v } from "convex/values";
// Generate upload URL for client-side uploads
export const generateUploadUrl = mutation({
args: {},
returns: v.string(),
handler: async (ctx) => {
return await ctx.storage.generateUploadUrl();
},
});
// Get file URL from storage ID
export const getFileUrl = query({
args: { storageId: v.id("_storage") },
returns: v.union(v.string(), v.null()),
handler: async (ctx, args) => {
return await ctx.storage.getUrl(args.storageId);
},
});