Skip to content

Issue when uploading a file with multipart/form-data with Chrome but trying to upload a directory instead of a file  #757

Open
@JosephHalter

Description

@JosephHalter
[debug] ** (Plug.Parsers.ParseError) malformed request, a MatchError exception was raised with message "no match of right hand side value: {:error, :closed}"
    (plug) lib/plug/conn.ex:1045: Plug.Conn.read_multipart_from_buffer_or_adapter/4
    (plug) lib/plug/conn.ex:936: Plug.Conn.read_part_headers/2
    (plug) lib/plug/parsers/multipart.ex:64: Plug.Parsers.MULTIPART.parse_multipart/2
    (plug) lib/plug/parsers/multipart.ex:34: Plug.Parsers.MULTIPART.parse/5
    (plug) lib/plug/parsers.ex:271: Plug.Parsers.reduce/7
    (app) lib/app_web/endpoint.ex:1: AppWeb.Endpoint.plug_builder_call/2
    (app) lib/plug/debugger.ex:122: AppWeb.Endpoint."call (overridable 3)"/2
    (app) lib/app_web/endpoint.ex:1: AppWeb.Endpoint.call/2
    (plug) lib/plug/adapters/cowboy/handler.ex:16: Plug.Adapters.Cowboy.Handler.upgrade/4
    (cowboy) /Sites/api/deps/cowboy/src/cowboy_protocol.erl:442: :cowboy_protocol.execute/4

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:

curl 'http://127.0.0.1:4000/app/batch' -H 'Accept: application/vnd.api+json' -H 'Referer: http://app.test:4200/submit?batch=true' -H 'Origin: http://app.test:4200' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36' -H 'Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryUhoiSH3D5xDbVVAz' --data-binary $'------WebKitFormBoundaryUhoiSH3D5xDbVVAz\r\nContent-Disposition: form-data; name="file"; filename="Flow Chart.gstencil"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n------WebKitFormBoundaryUhoiSH3D5xDbVVAz--\r\n' --compressed

I'm using Plug version 1.6.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions