Skip to content

Commit 4aa7535

Browse files
authored
enhance getUrl method to accept optional expiration time for signed URLs (#6)
1 parent bc5727d commit 4aa7535

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/client/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,16 @@ export class R2 {
144144
* Get a signed URL for serving an object from R2.
145145
*
146146
* @param key - The R2 object key.
147+
* @param options - Optional config object.
148+
* - `expiresIn` - The number of seconds until the URL expires (default: 3600, max: 604800 for 7 days).
147149
* @returns A promise that resolves to a signed URL for the object.
148150
*/
149-
async getUrl(key: string) {
151+
async getUrl(key: string, options: { expiresIn?: number } = {}) {
152+
const { expiresIn = 3600 } = options;
150153
return await getSignedUrl(
151154
this.r2,
152-
new GetObjectCommand({ Bucket: this.config.bucket, Key: key })
155+
new GetObjectCommand({ Bucket: this.config.bucket, Key: key }),
156+
{ expiresIn }
153157
);
154158
}
155159
/**

0 commit comments

Comments
 (0)