DEV Community

Discussion on: File upload using Laravel and Vue.js (The Right Way)

Collapse
 
bhaidar profile image
Bilal Haidar

Hello Diogo,

If you have complex data as arrays or nested objects, you will have to convert them to JSON manually.

Why is that?

Collapse
 
diogoko profile image
Diogo Kollross

Because when making a request encoded as multipart/form-data (which is a requirement for file uploads) all you can send is a flat list of name=value pairs - where value may either be a string or a file.

If you try to add an array or an object directly to the FormData object, it will be implicitly converted to a string, which is probably not what you want (resulting in, for example, "[object Object]" or "12,15,28,55").