Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/r2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -645,10 +645,13 @@ 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,
// You are trying to create a record with an id.
// This is not allowed as we handle id generation for you.
// The id will be ignored.
// id: fileMetadata.id,
userId: fileMetadata.userId,
filename: fileMetadata.filename,
originalName: fileMetadata.originalName,
Expand All @@ -660,7 +663,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);

Expand All @@ -678,7 +681,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);
Expand Down
Loading