From 3be76b80bd5438da6431a2b324b18cd360c6c898 Mon Sep 17 00:00:00 2001 From: Balint Ujvari Date: Tue, 28 Jul 2026 11:45:06 +0200 Subject: [PATCH] fix: streamable data upload and preserve http request data --- src/api/bytes.ts | 3 ++- src/modules/data.ts | 3 ++- src/utils/http.ts | 8 +++++++- src/utils/type.ts | 6 +++--- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/api/bytes.ts b/src/api/bytes.ts index 7ca7b842..1f7e96ac 100644 --- a/src/api/bytes.ts +++ b/src/api/bytes.ts @@ -1,4 +1,5 @@ import { Optional } from 'cafe-utility' +import { Readable } from 'stream' import type { BeeRequestOptions, DownloadOptions, RedundantUploadOptions, ReferenceInformation } from '../types' import { UploadResult } from '../types' import { UploadResultBody } from '../types/schema/upload' @@ -18,7 +19,7 @@ const endpoint = 'bytes' export async function upload( requestOptions: BeeRequestOptions, - data: string | Uint8Array, + data: string | Uint8Array | Blob | Readable, postageBatchId: BatchId, options?: RedundantUploadOptions, ): Promise { diff --git a/src/modules/data.ts b/src/modules/data.ts index 8d41227b..4eb593aa 100644 --- a/src/modules/data.ts +++ b/src/modules/data.ts @@ -1,3 +1,4 @@ +import { Readable } from 'stream' import type { BeeRequestOptions, DownloadOptions, @@ -34,7 +35,7 @@ export class Data { */ async upload( postageBatchId: BatchId | Uint8Array | string, - data: string | Uint8Array, + data: string | Uint8Array | Blob | Readable, options?: RedundantUploadOptions, requestOptions?: BeeRequestOptions, ): Promise { diff --git a/src/utils/http.ts b/src/utils/http.ts index 9ab5a631..94d3be2d 100644 --- a/src/utils/http.ts +++ b/src/utils/http.ts @@ -39,7 +39,13 @@ export interface BeeRequestConfig extends RequestInit { * @param config Internal settings and/or Bee settings */ export async function http(options: BeeRequestOptions, config: BeeRequestConfig): Promise> { - const requestConfig: BeeRequestConfig = Objects.deepMerge3(DEFAULT_HTTP_CONFIG, config, options) + const rawData = config.data + const requestConfig: BeeRequestConfig = Objects.deepMerge3( + DEFAULT_HTTP_CONFIG, + { ...config, data: undefined }, + options, + ) + requestConfig.data = rawData if (options.signal) { requestConfig.signal = options.signal diff --git a/src/utils/type.ts b/src/utils/type.ts index b21888fe..7949f940 100644 --- a/src/utils/type.ts +++ b/src/utils/type.ts @@ -36,9 +36,9 @@ export function isTag(value: unknown): value is Tag { * @param value * @throws TypeError if not valid */ -export function assertData(value: unknown): asserts value is string | Uint8Array { - if (typeof value !== 'string' && !(value instanceof Uint8Array)) { - throw new TypeError('Data must be either string or Uint8Array!') +export function assertData(value: unknown): asserts value is string | Uint8Array | Blob | stream.Readable { + if (typeof value !== 'string' && !(value instanceof Uint8Array) && !(value instanceof Blob) && !isReadable(value)) { + throw new TypeError('Data must be either string, Uint8Array, Blob or Readable!') } }