Skip to content

Add createBlob util function in common #1622

@mtuchi

Description

@mtuchi

Problem

encodeFormBody can handle Blob and File values in json mode, but there's no ergonomic way for a caller to submit raw binary data (e.g. a Buffer) with a specific MIME type and filename. Without this, submitting files/binaries requires the caller to manually construct a Blob before passing it in.

Proposed Solution

Add a createBlob(data, type, filename) helper that returns a wrapped class instance (BlobEntry). encodeFormBody recognises BlobEntry values in json mode and converts them to a typed, named Blob before appending to the FormData.

Usage:

  import { createBlob, encodeFormBody } from '@openfn/language-common/util';
                                                                                                                                                
  const form = encodeFormBody({
    name: 'upload',                                                                                                                             
    file: createBlob(buffer, 'image/jpeg', 'photo.jpg'),                                                                                        
  });                                                                                                                                         
                              

Implementation

  • Add unexported BlobEntry class to packages/common/src/util/http.js
  • Add exported createBlob(data, type, filename) factory
  • Update encodeFormBody json mode to detect BlobEntry via instanceof and wrap in Blob with type + filename
  • Add unit tests covering the factory output and encoder integration

Files:

  • packages/common/src/util/http.js
  • packages/common/test/util/http.test.js

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

Status
No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions