Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/cloudflare/internal/images-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ interface ServiceEntrypointStub {
image: ReadableStream<Uint8Array> | ArrayBuffer,
options?: ImageUploadOptions
): Promise<ImageMetadata>;
directUploadUrl(options?: DirectUploadOptions): Promise<DirectUploadResult>;
list(options?: ImageListOptions): Promise<ImageList>;
}

Expand All @@ -271,6 +272,12 @@ class HostedImagesBindingImpl implements HostedImagesBinding {
return this.#fetcher.upload(image, options);
}

async directUploadUrl(
options?: DirectUploadOptions
): Promise<DirectUploadResult> {
return this.#fetcher.directUploadUrl(options);
}

async list(options?: ImageListOptions): Promise<ImageList> {
return this.#fetcher.list(options);
}
Expand Down
29 changes: 29 additions & 0 deletions src/cloudflare/internal/images.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,25 @@ interface ImageUpdateOptions {
creator?: string;
}

interface DirectUploadOptions {
id?: string;
requireSignedURLs?: boolean;
metadata?: Record<string, unknown>;
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;
Expand Down Expand Up @@ -186,6 +205,16 @@ interface HostedImagesBinding {
options?: ImageUploadOptions
): Promise<ImageMetadata>;

/**
* 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<DirectUploadResult>;

/**
* List hosted images with pagination
* @param options List configuration
Expand Down
29 changes: 29 additions & 0 deletions types/defines/images.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,25 @@ interface ImageUpdateOptions {
creator?: string;
}

interface DirectUploadOptions {
id?: string;
requireSignedURLs?: boolean;
metadata?: Record<string, unknown>;
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;
Expand Down Expand Up @@ -183,6 +202,16 @@ interface HostedImagesBinding {
options?: ImageUploadOptions
): Promise<ImageMetadata>;

/**
* 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<DirectUploadResult>;

/**
* List hosted images with pagination
* @param options List configuration
Expand Down
Loading