-
-
Notifications
You must be signed in to change notification settings - Fork 314
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
When using FormRequest with 'file' validation, request data is empty even data is provided in docs example body #764
Comments
Having similar trouble here using try-it-out. Route uses HTTP PUT method and has a "file" parameter named "photo". #257 should have fixed this problem, but the HTTP method is never changed to POST, the hidden parameter "_method" is never added and the Content-Type header is never changed to multipart/form-data. The file is never seen by the server (as expected since PUT does not support multipart/form-data in PHP) and because of that the validation logic fails, stating the file is invalid since it is encoded as an empty JSON body.
The request header, as per the browser developer tools is not changed from "Content-Type: application/json" If I change the header manually to "multipart/form-data", the validation logic passes (the file is not mandatory), but the try-it-out does not send anything multipart encoded (file is missing), nothing is done at all regarding the file. The correct (manually changed) Content-Type is sent, but (if I am not understanding something wrong), it should be deleted (line 192) Edit: version here is 4.25.0 |
Thanks for your preliminary investigation. I'll look at this some more when I have the time, but in the meantime, feel free to submit a PR if you have an idea what needs to be fixed. |
When uploading a file the https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest_API/Using_FormData_Objects You can add following code to // ...
let preflightPromise = Promise.resolve();
if (window.useCsrf && window.csrfUrl) {
preflightPromise = makeAPICall('GET', window.csrfUrl).then(() => {
headers['X-XSRF-TOKEN'] = getCookie('XSRF-TOKEN');
});
}
// START this needs to be added
if (form.dataset.hasfiles === "1") {
delete headers['Content-Type'];
}
// END this needs to be added
return preflightPromise.then(() => makeAPICall(method, path, body, query, headers, endpointId))
// ... |
Can you make a PR with that fix? |
Scribe version
4.23
PHP version
8.2.4
Framework
Laravel
Framework version
10
Scribe config
What happened?
In my FormRequest, i have these rules:
In the generated documentation, within the "try_out" body, I can now choose the file I need to upload. However, when I hit submit, the response states, 'The information field is required,' even though I have already provided the value.
also the request payload:
request headers :
Content-Type: 'multipart/form-data'
Accept: 'application/json'
Docs
The text was updated successfully, but these errors were encountered: