denniske
denniske3mo ago

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",

});
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?
4 Replies
Convex Bot
Convex Bot3mo ago
Thanks for posting in <#1088161997662724167>. Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets. - Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.) - Use search.convex.dev to search Docs, Stack, and Discord all at once. - Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI. - Avoid tagging staff unless specifically instructed. Thank you!
erquhart
erquhart2mo ago
That's fair, it should be possible to overwrite. If you open an issue on the repo I can get to it, or feel free to PR (or just run a fork) if you need it sooner.
denniske
denniskeOP2mo ago
GitHub
Replace file on R2 using @convex-dev/r2 · Issue #3 · erquhart/con...
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); ...
denniske
denniskeOP2mo ago
thank you ❤️

Did you find this page helpful?