DEV Community

Chidiebere Chukwudi
Chidiebere Chukwudi

Posted on

2 1 1

Empty requests data with multipart/form-data when using fetch api

It took me quite some time to resolve this isssue. It was an issue with formData and laravel/php not being able to detect the request payload when I dd or dump the request to check.

There is (and I believe) other solutions but I think this will save you the need to do "messy" workarounds.

Here you go:

DO NOT specify the Content-Type header yourself, when trying to make such a multipart request. That header needs to include the boundary value (so that the receiver will know how to parse this request) - if you specify it yourself, as just multipart/form-data, then that will be missing.

These…

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay