Skip to content

Commit d96a91f

Browse files
mishushakovclaude
andcommitted
fixup: default octet-stream upload to false; keep version check as guard
Default `useOctetStream` / `use_octet_stream` to `false` so file write goes through `multipart/form-data` regardless of envd version. Callers opt in explicitly; the existing envd version check remains and gates the opt-in path so older envds fall back to multipart. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 573e2ba commit d96a91f

3 files changed

Lines changed: 19 additions & 6 deletions

File tree

packages/js-sdk/src/sandbox/filesystem/index.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import type { Timestamp } from '@bufbuild/protobuf/wkt'
2929
import { compareVersions } from 'compare-versions'
3030
import {
3131
ENVD_DEFAULT_USER,
32+
ENVD_OCTET_STREAM_UPLOAD,
3233
ENVD_VERSION_RECURSIVE_WATCH,
3334
} from '../../envd/versions'
3435
import {
@@ -174,7 +175,8 @@ export interface FilesystemWriteOpts extends FilesystemRequestOpts {
174175
/**
175176
* When true, the upload uses `application/octet-stream` instead of `multipart/form-data`.
176177
*
177-
* Defaults to `false`. Requires envd 0.5.7 or later.
178+
* Defaults to `false`. Requires envd 0.5.7 or later — when not supported by
179+
* the sandbox's envd version, the upload falls back to `multipart/form-data`.
178180
*/
179181
useOctetStream?: boolean
180182
}
@@ -420,7 +422,10 @@ export class Filesystem {
420422
user = defaultUsername
421423
}
422424

423-
const useOctetStream = writeOpts?.useOctetStream ?? false
425+
const supportsOctetStream =
426+
compareVersions(this.envdApi.version, ENVD_OCTET_STREAM_UPLOAD) >= 0
427+
const useOctetStream =
428+
(writeOpts?.useOctetStream ?? false) && supportsOctetStream
424429

425430
const results: WriteInfo[] = []
426431

packages/python-sdk/e2b/sandbox_async/filesystem/filesystem.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from e2b.envd.rpc import authentication_header, handle_rpc_exception
2121
from e2b.envd.versions import (
2222
ENVD_DEFAULT_USER,
23+
ENVD_OCTET_STREAM_UPLOAD,
2324
ENVD_VERSION_RECURSIVE_WATCH,
2425
)
2526
from e2b.exceptions import (
@@ -209,7 +210,7 @@ async def write(
209210
:param user: Run the operation as this user
210211
:param request_timeout: Timeout for the request in **seconds**
211212
:param gzip: Use gzip compression for the request
212-
:param use_octet_stream: Upload using `application/octet-stream` instead of `multipart/form-data`. Defaults to `False`. Requires envd 0.5.7 or later.
213+
:param use_octet_stream: Upload using `application/octet-stream` instead of `multipart/form-data`. Defaults to `False`. Requires envd 0.5.7 or later — when not supported, the upload falls back to `multipart/form-data`.
213214
214215
:return: Information about the written file
215216
"""
@@ -246,7 +247,7 @@ async def write_files(
246247
:param user: Run the operation as this user
247248
:param request_timeout: Timeout for the request
248249
:param gzip: Use gzip compression for the request
249-
:param use_octet_stream: Upload using `application/octet-stream` instead of `multipart/form-data`. Defaults to `False`. Requires envd 0.5.7 or later.
250+
:param use_octet_stream: Upload using `application/octet-stream` instead of `multipart/form-data`. Defaults to `False`. Requires envd 0.5.7 or later — when not supported, the upload falls back to `multipart/form-data`.
250251
:return: Information about the written files
251252
"""
252253
username = user
@@ -256,6 +257,9 @@ async def write_files(
256257
if len(files) == 0:
257258
return []
258259

260+
supports_octet_stream = self._envd_version >= ENVD_OCTET_STREAM_UPLOAD
261+
use_octet_stream = use_octet_stream and supports_octet_stream
262+
259263
results: List[WriteInfo] = []
260264

261265
if use_octet_stream:

packages/python-sdk/e2b/sandbox_sync/filesystem/filesystem.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from e2b.envd.rpc import authentication_header, handle_rpc_exception
2121
from e2b.envd.versions import (
2222
ENVD_DEFAULT_USER,
23+
ENVD_OCTET_STREAM_UPLOAD,
2324
ENVD_VERSION_RECURSIVE_WATCH,
2425
)
2526
from e2b.exceptions import (
@@ -207,7 +208,7 @@ def write(
207208
:param user: Run the operation as this user
208209
:param request_timeout: Timeout for the request in **seconds**
209210
:param gzip: Use gzip compression for the request
210-
:param use_octet_stream: Upload using `application/octet-stream` instead of `multipart/form-data`. Defaults to `False`. Requires envd 0.5.7 or later.
211+
:param use_octet_stream: Upload using `application/octet-stream` instead of `multipart/form-data`. Defaults to `False`. Requires envd 0.5.7 or later — when not supported, the upload falls back to `multipart/form-data`.
211212
212213
:return: Information about the written file
213214
"""
@@ -242,7 +243,7 @@ def write_files(
242243
:param user: Run the operation as this user
243244
:param request_timeout: Timeout for the request
244245
:param gzip: Use gzip compression for the request
245-
:param use_octet_stream: Upload using `application/octet-stream` instead of `multipart/form-data`. Defaults to `False`. Requires envd 0.5.7 or later.
246+
:param use_octet_stream: Upload using `application/octet-stream` instead of `multipart/form-data`. Defaults to `False`. Requires envd 0.5.7 or later — when not supported, the upload falls back to `multipart/form-data`.
246247
:return: Information about the written files
247248
"""
248249
username = user
@@ -252,6 +253,9 @@ def write_files(
252253
if len(files) == 0:
253254
return []
254255

256+
supports_octet_stream = self._envd_version >= ENVD_OCTET_STREAM_UPLOAD
257+
use_octet_stream = use_octet_stream and supports_octet_stream
258+
255259
results: List[WriteInfo] = []
256260

257261
if use_octet_stream:

0 commit comments

Comments
 (0)