CORS problem if "Content-type": "multipart/form-data"
I have the same problem ,Requests (GET/POST/PUT/DELTE) all work, only fileupload with Content-type:"multipart/form-data" got the CORS problem. I tried many times with headers "Access-Control-Allow-Origin ,Access-Control-Allow-Methods, Access-Control-Allow-Headers". Still not work
Finally, I found the nginx limited the File Upload Size. So, I add "client_max_body_size 10M" in nginx conf file.
The cors problem solved.
Solved it by applying CORS in application side.
In detail, when browser sends preflight request error comes out. So, for the preflight requests I manually added Headers in application side. I have been using Laravel for backend, so created Cors middleware as floowing:
public function handle($request, Closure $next) {
if ($request->getMethod() == "OPTIONS") {
$headers = [
'Access-Control-Allow-Methods' => 'POST, GET, OPTIONS, PUT, DELETE',
'Access-Control-Allow-Headers' => 'Content-Type, Origin, Authorization'
];
return \Response::make('OK', 200, $headers);
}
return $next($request);
}