denniskeD
Convex Community7mo ago
4 replies
denniske

Cannot replace file on R2 using @convex-dev/r2

hi, I want to store translation files for my app on R2. So when new translations are published I need to replace the file on R2 using the following code:

        const json = JSON.stringify(translations);
        const jsonBuffer = new TextEncoder().encode(json);

        const key = await r2.store(ctx, jsonBuffer, {
            key: `translations/${baseline.language}.json`,
            type: "application/json",

        });


I get the following error:
6/22/2025, 1:46:21 PM [CONVEX A(changeset:storeBlobForBaseline)] Uncaught Error: Metadata already exists for key translations/ms.json. Please use a unique key.
at store [as store] (../node_modules/@convex-dev/r2/src/client/index.ts:204:81)
at async handler (../convex/changeset.ts:222:17)

I know I can delete the file and store it again, but do you know a better way?
Was this page helpful?