How big is the file attachment?
Request' Input parameter is empty
I'm trying to send a request from my front-end to Laravel. But Laravel doesn't seem to catch it.
Here's my code from client (JS)
return new Promise((resolve, reject) => {
let formData = new FormData();
formData.append('attachment', data.attachment);
formData.append('title', data.title);
formData.append('content', data.content);
formData.append('publish_on', data.publish_on);
axios.put('some/url/1', formData, {
headers: {
'Content-Type': 'multipart/form-data'
}
}).then(response => {
resolve(response);
}).catch(error => {
reject(error);
});
});
For testing, I just dump the input from web.php
Route::put('some/url/{something}', function (Request $request) {
dd(\Input::all()); // returns an empty array
dd($request->input('title')); // returns a null
});
I'm sure the data has been pass to the server because when I click the Network tab on Chrome Developer Tools, I see it in my Request Payload.
The payload contains:
------WebKitFormBoundaryWmkUAKZRhAmLrvit
Content-Disposition: form-data; name="attachment"; filename="Sample.xlsx"
Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
------WebKitFormBoundaryWmkUAKZRhAmLrvit
Content-Disposition: form-data; name="title"
The Title
------WebKitFormBoundaryWmkUAKZRhAmLrvit
Content-Disposition: form-data; name="content"
The Content
------WebKitFormBoundaryWmkUAKZRhAmLrvit
Content-Disposition: form-data; name="publish_on"
12-30-2016
------WebKitFormBoundaryWmkUAKZRhAmLrvit--
I need to use FormData here because I'm sending a file. This only happens when updating the resource. The creation is working fine.
PS: I'm using ES2016 syntax
After long hours of thoroughly searching the web, I found out that uploading a file on a PUT request is currently not allowed.
For reference, here's the link to the issue
Input from PUT requests sent as multipart/form-data is unavailable
Please or to participate in this conversation.