diff --git a/src/cloudflare/internal/images-api.ts b/src/cloudflare/internal/images-api.ts index efe33b99174..cbc0a2db496 100644 --- a/src/cloudflare/internal/images-api.ts +++ b/src/cloudflare/internal/images-api.ts @@ -250,6 +250,7 @@ interface ServiceEntrypointStub { image: ReadableStream | ArrayBuffer, options?: ImageUploadOptions ): Promise; + directUploadUrl(options?: DirectUploadOptions): Promise; list(options?: ImageListOptions): Promise; } @@ -271,6 +272,12 @@ class HostedImagesBindingImpl implements HostedImagesBinding { return this.#fetcher.upload(image, options); } + async directUploadUrl( + options?: DirectUploadOptions + ): Promise { + return this.#fetcher.directUploadUrl(options); + } + async list(options?: ImageListOptions): Promise { return this.#fetcher.list(options); } diff --git a/src/cloudflare/internal/images.d.ts b/src/cloudflare/internal/images.d.ts index 60ee8612186..f619e6d3512 100644 --- a/src/cloudflare/internal/images.d.ts +++ b/src/cloudflare/internal/images.d.ts @@ -125,6 +125,25 @@ interface ImageUpdateOptions { creator?: string; } +interface DirectUploadOptions { + id?: string; + requireSignedURLs?: boolean; + metadata?: Record; + creator?: string; + expiresAt?: Date; +} + +interface DirectUploadResult { + /** + * The ID of the image that will be created once it is uploaded + */ + id: string; + /** + * The one-time URL that a creator can upload an image to + */ + uploadURL: string; +} + interface ImageListOptions { limit?: number; cursor?: string; @@ -186,6 +205,16 @@ interface HostedImagesBinding { options?: ImageUploadOptions ): Promise; + /** + * Create a one-time authenticated URL that a creator can upload an image to + * directly, without exposing your API token. + * @see https://developers.cloudflare.com/images/storage/upload-images/direct-creator-upload/ + * @param options Direct upload configuration + * @returns The upload URL and the ID the uploaded image will be given + * @throws {@link ImagesError} if the URL cannot be created + */ + directUploadUrl(options?: DirectUploadOptions): Promise; + /** * List hosted images with pagination * @param options List configuration diff --git a/types/defines/images.d.ts b/types/defines/images.d.ts index 672eabe0273..22440a13c41 100644 --- a/types/defines/images.d.ts +++ b/types/defines/images.d.ts @@ -122,6 +122,25 @@ interface ImageUpdateOptions { creator?: string; } +interface DirectUploadOptions { + id?: string; + requireSignedURLs?: boolean; + metadata?: Record; + creator?: string; + expiresAt?: Date; +} + +interface DirectUploadResult { + /** + * The ID of the image that will be created once it is uploaded + */ + id: string; + /** + * The one-time URL that a creator can upload an image to + */ + uploadURL: string; +} + interface ImageListOptions { limit?: number; cursor?: string; @@ -183,6 +202,16 @@ interface HostedImagesBinding { options?: ImageUploadOptions ): Promise; + /** + * Create a one-time authenticated URL that a creator can upload an image to + * directly, without exposing your API token. + * @see https://developers.cloudflare.com/images/storage/upload-images/direct-creator-upload/ + * @param options Direct upload configuration + * @returns The upload URL and the ID the uploaded image will be given + * @throws {@link ImagesError} if the URL cannot be created + */ + directUploadUrl(options?: DirectUploadOptions): Promise; + /** * List hosted images with pagination * @param options List configuration