Attach the file to ajax request

Hi! I need help. I try to attach the file to ajax request. but on the backend i can’t access it.$this->request->getUploadedFiles() is empty. But $_FILES i can get all necessary information.

How does it???

What Content-Type header are you sending with your request?

1 Like

I have a separate property ContentType property: with a value of false; Whether to insert ContentType in headers???

I can’t remember details right now, but I believe there’s some specific header that comes with the POST request that a Cake form with 'type' => 'file' generates, which controls whether or not it parses $_FILES. Hopefully this will help, or someone else can jump in with the specifics.

Try whole name space:

Uploaded files can also be accessed as objects separately from the request data via the Cake\Http\ServerRequest::getUploadedFile() and Cake\Http\ServerRequest::getUploadedFiles() methods. These methods will always return objects, irrespectively of the App.uploadedFilesAsObjects configuration.

Request & Response Objects - 4.x

Scroll down a little. But I just use $_FILES also.