diff --git a/src/r2.ts b/src/r2.ts index 586aa19..144c45f 100644 --- a/src/r2.ts +++ b/src/r2.ts @@ -653,10 +653,9 @@ export const createR2Endpoints = ( // Store file metadata in database try { - await ctx.context.adapter.create({ + const newFile = await ctx.context.adapter.create({ model: modelName, data: { - id: fileMetadata.id, userId: fileMetadata.userId, filename: fileMetadata.filename, originalName: fileMetadata.originalName, @@ -668,7 +667,7 @@ export const createR2Endpoints = ( }, }); - ctx.context.logger?.info("[R2]: File metadata saved to database:", fileMetadata.id); + ctx.context.logger?.info("[R2]: File metadata saved to database:", newFile.id); } catch (dbError) { ctx.context.logger?.error("[R2]: Failed to save to database:", dbError); @@ -686,7 +685,7 @@ export const createR2Endpoints = ( return ctx.json({ success: true, - data: fileMetadata, + data: { ...fileMetadata, id: newFile.id }, }); } catch (error) { ctx.context.logger?.error("[R2]: Upload failed:", error);