Skip to content
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

file_upload broken: example adds newline before EOF on upload #258

Open
lindig opened this issue Jan 24, 2021 · 3 comments
Open

file_upload broken: example adds newline before EOF on upload #258

lindig opened this issue Jan 24, 2021 · 3 comments

Comments

@lindig
Copy link

lindig commented Jan 24, 2021

A file uploaded with the server in /example/file_upload is not identical to the original file as can be verified with a checksum. I believe a newline is added at the end of the file.

  • Opium 0.20.0
  • OCaml 4.09.0
  • httpaf 0.7.0
  • Lwt 5.4.0

To reproduce the bug, upload a file with the demo application (either the simple or more styled one) and compare the uploaded file against the original. If this bug is indeed universal, this would render uploading images and other binary formats impossible.

@lindig
Copy link
Author

lindig commented Jan 24, 2021

Switching to https://github.com/dinosaure/multipart_form could be an option. Other people reported issues around handling of \r\n in the library that is currently used multipart-form-data library for form decoding.

@lindig
Copy link
Author

lindig commented Feb 28, 2021

I've verified this with uploading a PNG file using the simple (unstyled) upload example. The uploaded file has two extra bytes at the end, which is also evident from the file size. Can anybody confirm or reject this bug?

@panglesd
Copy link

panglesd commented Mar 15, 2021

I have the same issue.

An unsatisfactory fix is to remove the last two characters.

For instance, in the opium example, change the close function to this:

  let close filename file prev =
    let* () = prev in
    let* () = Lwt_unix.close file in
    let new_size = (Unix.stat filename).st_size - 2 in
    Lwt.return @@ Unix.truncate filename new_size

@lindig lindig changed the title file_upload example adds newline before EOF on upload file_upload broken: example adds newline before EOF on upload Mar 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants