tomaka / rouille

Web framework in Rust
Apache License 2.0
1.09k stars 105 forks source link

HTML file upload error #210

Open spasius opened 5 years ago

spasius commented 5 years ago

Error then trying to upload html file (source from examples): {"description":"failed to parse a requested field","cause":{"description":"expected a file but got a field, or vice versa","cause":null}}

NGgmnBQGwR commented 4 years ago

I've encountered the same issue. Posting more information, in case it's needed.

Server returns 400 with error:

{"description":"failed to parse a requested field","cause":{"description":"expected a file but got a field, or vice versa","cause":null}}

if you upload any text file. But if you rename the file to something else, then it can be uploaded successfully.

Steps to reproduce:

  1. Start example: cargo run --example simple-form

  2. Create text file: echo "Hello, world" > test.txt

  3. Open http://localhost:8000/ in browser and try to upload "text.txt". It will fail with 400.

  4. Rename this file: mv test.txt test.txt1

  5. Try to upload "text.txt1". It will succeed.

But I'm not experienced enough to to say whether it's a problem with example code or with rouille itself.

PixelCoda commented 2 years ago

I can verify this bug still exists on rouille v3.4.0 and it also applies to .HTML files. It appears to be a conflict between the BufferedFile struct type and plain text uploads.

Update: It works if you use a String instead of BufferedFile, but the sacrifice is compatibility for .png and other non-text file types.