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
Problem
encodeFormBodycan 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 specificMIME typeand filename. Without this, submitting files/binaries requires the caller to manually construct aBlobbefore 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:
Implementation
BlobEntryclass to packages/common/src/util/http.jsFiles: