Skip to content
Advertisement

POST file along with form data Vue + axios

I have a method for Vuejs component:

JavaScript

And in test.php, I’m using json_decode(file_get_contents("php://input"), TRUE); to read data as $_POST variables.

While I am able to read name, gender and dob correctly, I can’t fetch avatar properly.

Any solutions for the same?

Note: I don’t to append every variable as formData.append(.., ..) as I am planning to handle over 14 variables.

Note for moderators: I didn’t find any question where formData was being used along with other data objects.

Advertisement

Answer

So, I figured this one out in a simpler way:

JavaScript

test.php:

JavaScript

Note: I had an option of using:

JavaScript

but since I was dealing with nested objects (name: { first: '', last: ''} ) in rawData, I chose not to do that as it would require recursive methods on either client side or server side.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement