Fix file upload through htmx.ajax #2778
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #2630
Description
When converting an object to FormData, we had a simple check that if a value was an object, we'd JSON-stringify it before appending it to the FormData.
#2748 addressed a similar issue, thoughI had totally missed that a similar check was done elsewhere in the code.
One case was not handled here, causing the referenced issue ; the
Blob
type, thatFormData
can perfectly handle (a type that includesFile
s), would be JSON-stringified instead of directly passed toFormData.append
as it's anobject
itself, resulting in the loss of the file data, and that conversion to an empty object.Corresponding issue: #2630
Testing
Added a test cases, to ensure that
htmx.ajax
with a file passed in parameters, is correctly uploaded and not empty.Also added another test case with a file input as I found out we didn't have any yet.
Additionnaly, you can:
Checklist
master
for website changes,dev
forsource changes)
approved via an issue
npm run test
) and verified that it succeeded