Skip to content

uploadPieceStreaming

uploadPieceStreaming(options): Promise<OutputType>

Defined in: packages/synapse-core/src/sp/upload-streaming.ts:100

Upload piece data using the 3-step CommP-last streaming protocol.

Protocol:

  1. POST /pdp/piece/uploads → get upload session UUID
  2. PUT /pdp/piece/uploads/{uuid} → stream data while calculating CommP
  3. POST /pdp/piece/uploads/{uuid} → finalize with calculated CommP
  4. With waitForParked, GET /pdp/piece?pieceCid={pieceCid} until the piece is parked
Parameter Type Description
options OptionsType uploadPieceStreaming.OptionsType

Promise<OutputType>

PieceCID and size of uploaded data uploadPieceStreaming.OutputType

import { createReadStream } from 'node:fs'
import * as SP from '@filoz/synapse-core/sp'

const { pieceCid, size } = await SP.uploadPieceStreaming({
  serviceURL: 'https://pdp.example.com',
  data: createReadStream('./file.bin'),
  waitForParked: true,
})

Errors uploadPieceStreaming.ErrorType