You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
However, this is annoying to have to do. I think it would be great if Inertia could detect if the data object includes files, and if it does, convert it to a FormData object.
// automatically if data includes filesInertia.post('/users',data)
While implementing this, it would be good to tackle this issue as well: #236
Reference
Laravel Jetstream already does this automatically (see here, here and here).
Axios also does some work to detect if a file is included (see here).
Booleans
When submitting data as a FormData object, the data is no longer json, meaning any boolean values will become strings values ("true" and "false"). I think we can simply convert these to 1 or 0.
Multi-dimensional objects
In addition to converting booleans, we'll also have to convert multi-dimensional objects. Something like this:
This discussion was converted from issue #270 on December 19, 2020 17:27.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
In order to upload files with Inertia, you have to convert your
data
object to aFormData
object:However, this is annoying to have to do. I think it would be great if Inertia could detect if the
data
object includes files, and if it does, convert it to aFormData
object.While implementing this, it would be good to tackle this issue as well: #236
Reference
Laravel Jetstream already does this automatically (see here, here and here).
Axios also does some work to detect if a file is included (see here).
Booleans
When submitting data as a
FormData
object, the data is no longerjson
, meaning any boolean values will become strings values ("true"
and"false"
). I think we can simply convert these to1
or0
.Multi-dimensional objects
In addition to converting booleans, we'll also have to convert multi-dimensional objects. Something like this:
Becomes:
Beta Was this translation helpful? Give feedback.
All reactions