Repository navigation
fix(types): add optional value to MultipartFile for onFile - #624
Conversation
is2ei
left a comment
There was a problem hiding this comment.
I think the issue is a bit more complicated.
It looks like assigning the value field to the part object in the onFile function is a bit of a hack.
This works because the if statement uses field.value when it is not undefined.
if (field.value !== undefined) {
body[key] = field.value
} else if (field._buf) {
body[key] = field._bufHowever, the value property is intended for objects whose type is field.
const value = {
type: 'field',
fieldname: name,
mimetype: contentType,
encoding,
value: fieldValue,
fieldnameTruncated,
valueTruncated,
fields: body
}On the other hand, the _buf property is intended for objects whose type is file.
const value = {
type: 'file',
fieldname: name,
filename,
encoding,
mimetype,
file,
fields: body,
_buf: null,
async toBuffer () {d8def27 to
513afe6
Compare
|
@is2ei I checked the file-part behavior against the current README and the existing custom- |
Add optional
value?: unknowntoMultipartFileso the documentedonFileexample forattachFieldsToBody: 'keyValues'typechecks. The type regression now uses that decoding example.The existing custom-
onFileruntime test verifies that the assigned file value reaches the request body. No runtime change is needed.Validation:
npm testpassed (103 runtime tests, 100% coverage and 35 type assertions);npm run lintpassed.Fixes #574