Skip to content

MultipartUploader: partSizeMB is actually bytes, and resume state is dead code #91

Description

@yash-sangwan

Three problems tangled together in this class.

The unit is wrong. The config field is called partSizeMB but it is compared against 5 * 1024 * 1024 and assigned straight to a byte count. UploadManager happens to pass bytes so it works, but BYOS3ApiProvider.uploadMultipartParallely forwards params.partSizeMB from the caller untouched. Anyone passing 10 meaning 10MB fails the >= 5242880 check and silently gets 5MB parts instead.

Resume can never work. The constructor calls localStorage.removeItem for this key, and saveState writes to that same key after every part. So a fresh uploader wipes the saved state before anything could read it. Nothing ever calls a restore path. The persistence is write-only.

It breaks outside the browser. That localStorage call sits in the constructor of a package whose tsconfig targets Node (module: NodeNext) and whose own test suite runs in environment: 'node'. Constructing a MultipartUploader server-side throws localStorage is not defined.

Where:

  • s3-api/src/utils/multipartUploader.ts (lines 33-38, 40-51, 150-184)
  • s3-api/src/core/types.ts (MultipartUploadParams, MultipartUploadConfig)
  • s3-api/src/index.ts (uploadMultipartParallely)

What to do:

  • Pick one unit and name it honestly - either partSizeBytes, or keep MB and multiply inside the constructor
  • Guard localStorage behind a typeof window !== 'undefined' check, or inject a storage adapter
  • Either finish resume-across-reload (look up saved state by key on construction instead of deleting it) or delete saveState entirely - right now it is pure overhead writing JSON to localStorage after every part

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions