-
Notifications
You must be signed in to change notification settings - Fork 588
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
Issue when uploading a file with multipart/form-data with Chrome but trying to upload a directory instead of a file #757
Comments
Thanks @JosephHalter! Just to make sure we can confidently reproduce the bug, can you please provide a small app (either phoenix or plug) that we can submit a request too and reproduce the failure? Thanks! |
Ping! |
I've created a basic app here: https://github.com/JosephHalter/demo-phoenix-app Doing the same thing in Firefox (drag&dropping a directory instead of a file into a file input and submitting the form) creates a CURL request which is a little bit different, with a more helpful error message but it's still crashing with a 500 and not allowing me to return a 422 with a custom error message.
Result:
The initially reported error is still happening, however what Chrome inspector copies as cURL format doesn't match exactly what it does itself it seems as I don't get the same failure when I run it in the terminal. By capturing the request with Charles Proxy and getting the cURL request from here I get a version slightly different from Chrome:
Which also returns error request export and example of file causing the error.zip Also in this .zip is an example of something which look like a file for MacOS but it in fact a directory which I've use to recreate the issue. I'm not sure you've got everything you need to reproduce it, but I don't know what more I can do to help. |
Also, sorry for the delay I wanted to respond sooner but was on holiday. To sum up, selecting the provided "file" instead of a true file in a file input will, depending on the browser, trigger one of the following error message:
or also sometimes:
And what would be the best possible behaviour instead would be for the request to continue, go to the controller action with one of these 3 possibilities for the params:
Any of these would allow to be catched in the controller and to return a proper error message to the user such as "file is missing", "file in invalid", etc. so he can understand what is the issue. |
Was there a cause for the error, or better yet how to solve it? |
@sebastialonso I don't know any way that I could better describe the problem apart from what is already in this ticket. It's not really a bug because the request IS malformed indeed. There's nothing you can do to make the request go forward, the browser tried to upload a "file" but there's no file sent. However, the issue is more about how to handle the exception, when plug crashes instead of filling something inside the connection (for example like I suggested considering that it's a file with size 0) then it'll just be an error 500 without any feedback in production. |
I was able to create this while using postman: Create an endpoint expecting an image attribute to be provided Though I was able to create this scenario by sending a raw POST request with no data too. This is probably the correct response. It's just misleading when you see the phoenix error splash screen while running phx.server in dev, vs building the release and running it in prod config where it will return a 400 status. |
It's normal that the request can't proceed, but it would be better if it was possible to better catch the error. In dev when Plug.Parsers.ParseError is raised it doesn't return anything, not even 500. I didn't know that in production is returns 400. If it's the case it's already an improvement. Is there nothing else we can do to make it more user friendly? I'm not sure since it's been so long but I think that the problem is that when it crashes at the parsing level, it doesn't even go through the router. |
Since plug crashes the server doesn't even return error 500, I would prefer to be able to return a proper response saying that the file seem invalid or something.
As a curl request from Chrome inspector:
I'm using Plug version 1.6.2
The text was updated successfully, but these errors were encountered: