Skip to content

Commit

Permalink
bug (refs T35953): Don't stringify form data (703)
Browse files Browse the repository at this point in the history
If you stringify a form data object you get an empty object. For form post we need to send the form data as it is.
  • Loading branch information
gruenbergerdemos authored Jan 9, 2024
1 parent 719427f commit ee22246
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ Since v0.0.10, this Changelog is formatted according to the [Common Changelog][c

## UNRELEASED

### Fixed

- ([#703](https://github.com/demos-europe/demosplan-ui/pull/703)) Don't stringify form data for post requests ([@gruenbergerdemos](https://github.com/gruenbergerdemos))

## v0.3.4 - 2024-01-05

### Fixed
Expand Down
8 changes: 6 additions & 2 deletions src/lib/DpApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ const doRequest = (async ({ url, method = 'GET', data = {}, params, options = {}
}

if (method.toUpperCase() !== 'GET') {
payload.body = JSON.stringify(data)
if (data instanceof FormData) {
payload.body = data
} else {
payload.body = JSON.stringify(data)
}
} else if (options.serialize === true) {
delete payload.options.serialize

Expand Down Expand Up @@ -202,7 +206,7 @@ function makeFormPost (payload, url) {
}

return dpApi({
method: 'post',
method: 'POST',
url: url,
data: postData,
headers: { 'Content-Type': 'multipart/form-data' }
Expand Down

0 comments on commit ee22246

Please sign in to comment.