Skip to content

Pass in customKey to generateUploadUrl #12

@moosashah

Description

@moosashah

The generateUploadUrl on the R2 class takes in a customKey param

r2/src/client/index.ts

Lines 159 to 174 in 594a9b4

/**
* Generate a signed URL for uploading an object to R2.
*
* @param customKey (optional) - A custom R2 object key to use. Must be unique.
* @returns A promise that resolves to an object with the following fields:
* - `key` - The R2 object key.
* - `url` - A signed URL for uploading the object.
*/
async generateUploadUrl(customKey?: string) {
const key = customKey || crypto.randomUUID();
const url = await getSignedUrl(
this.r2,
new PutObjectCommand({ Bucket: this.config.bucket, Key: key })
);
return { key, url };
}

but the generateUploadUrl mutation returned from the client doesn't take in a customKey

r2/src/client/index.ts

Lines 349 to 361 in 594a9b4

generateUploadUrl: mutationGeneric({
args: {},
returns: v.object({
key: v.string(),
url: v.string(),
}),
handler: async (ctx) => {
if (opts?.checkUpload) {
await opts.checkUpload(ctx, this.config.bucket);
}
return this.generateUploadUrl();
},
}),

would be really nice to be able to pass in a customKey as an optional arg to the mutation.

Currently we'd have to create a mutation which could take in a key if we want to use a custom key

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions