Start typing to search...

UI.upload

Uploads files from the frontend of your Koji app directly to your project’s CDN.

Methods

.uploadFile(options)

Uploads a file to your project’s CDN. Use this method to provide a custom upload experience or to upload media created or captured during the app experience. For example, recording a video or drawing on a canvas.

To upload files with the standard platform control, use {@doclink core-frontend-ui-capture#file | Capture.file }.

Note
To use this method for uploading a file collected by a file input, you must extract the blob and reconstruct the file. Browser sandboxing will not allow the native file to be transferred.

Parameters

  • options - UploadOptions, Request options for a [[uploadFile | file upload]].

Returns

Promise<String>, Unique URL for accessing the file on `images.koji-cdn.com` or `objects.koji-cdn.com`, depending on the type of file.

Example

const url = await Koji.ui.upload.uploadFile({
 file: new File([blob], 'video.webm'),
 type: 'video',
 videoOptions: {
   hls: true,
 }
});

Source: frontend/ui/upload/index.ts#L61

Interfaces

UploadOptions

Request options for a [[uploadFile | file upload]].

Properties

  • file - File, File to upload.

  • silent - Boolean (Optional), Set to true to handle progress in the app instead of showing the Koji overlay

  • type - 'image' | 'video' | 'audio', Media type of the file, which is used to determine whether transcoding or other processing is required.

  • videoOptions - VideoOptions (Optional), Options for uploaded videos.

VideoOptions

Options for uploaded videos.

Properties

  • hls - Boolean (Optional), Enables HTTP Live Streaming (HLS) for delivery of longer content. When enabled, uploaded videos are transcoded for HLS and saved as an m3u8 playlist. Use this feature in conjunction with [[https://github.com/video-dev/hls.js/ | hls.js]] for controlling playback.

  • remux - Boolean (Optional), Remuxes video files constructed from getUserMedia MediaStreams, which ensures these files contain correct duration headers before they are delivered.

  • remuxPreset - RemuxPreset (Optional), Specifies the cropping constraints when remuxing a video. If not specified, the video will not be cropped.

  • watermark - Watermark (Optional), Applies a watermark to the uploaded image. Available only with HLS transcoding.

RemuxPreset

Specifies the cropping constraints when remuxing a video. If not specified, the video will not be cropped.

Properties

  • aspectRatio - '16:9' | '9:16' | '4:5' | '1:1' | 'passthrough', Desired aspect ratio.

  • sizePolicy - 'fill' | 'fit', How the image will be constrained within the provided size.

Watermark

Applies a watermark to the uploaded image. Available only with HLS transcoding.

Properties

  • type - 'creatorProfileUrl', Type of the watermark. `creatorProfileUrl` watermarks the image with `koji.to/@creatorUsername`.

VideoOptions

Options for uploaded videos.

Properties

  • hls - Boolean (Optional), Enables HTTP Live Streaming (HLS) for delivery of longer content. When enabled, uploaded videos are transcoded for HLS and saved as an m3u8 playlist. Use this feature in conjunction with [[https://github.com/video-dev/hls.js/ | hls.js]] for controlling playback.

  • remux - Boolean (Optional), Remuxes video files constructed from getUserMedia MediaStreams, which ensures these files contain correct duration headers before they are delivered.

  • remuxPreset - RemuxPreset (Optional), Specifies the cropping constraints when remuxing a video. If not specified, the video will not be cropped.

  • watermark - Watermark (Optional), Applies a watermark to the uploaded image. Available only with HLS transcoding.

RemuxPreset

Specifies the cropping constraints when remuxing a video. If not specified, the video will not be cropped.

Properties

  • aspectRatio - '16:9' | '9:16' | '4:5' | '1:1' | 'passthrough', Desired aspect ratio.

  • sizePolicy - 'fill' | 'fit', How the image will be constrained within the provided size.

Watermark

Applies a watermark to the uploaded image. Available only with HLS transcoding.

Properties

  • type - 'creatorProfileUrl', Type of the watermark. `creatorProfileUrl` watermarks the image with `koji.to/@creatorUsername`.