Skip to main content

Strategies Overview

WIP

Pluggable upload strategies for different backends and protocols.

Strategies implement the upload protocol and register with the engine. The engine picks one based on the strategy field on the intent returned by the backend.

Responsibilities

Each strategy:

  • Turns an intent into network calls.
  • Reports progress and persists cursor updates.
  • Honors abort signals for pause and cancel.

Available Strategies

StrategyUse CaseResumable
POSTSimple presigned form uploadsNo
MultipartLarge file uploads with concurrent partsYes

Registry

Install strategies via the registry helper before creating the store:

import { createStrategyRegistry, PostStrategy, multipartStrategy } from '@gentleduck/upload/strategies'
 
const registry = createStrategyRegistry()
registry.set(PostStrategy())
registry.set(multipartStrategy())
import { createStrategyRegistry, PostStrategy, multipartStrategy } from '@gentleduck/upload/strategies'
 
const registry = createStrategyRegistry()
registry.set(PostStrategy())
registry.set(multipartStrategy())

The registry enforces typed strategy keys through the intent map, keeping the backend intent response and the strategy implementation in sync.

See Strategy Registry for more.