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

Avoid create multiple large copies of uploaded file data in memory #286

Merged
merged 3 commits into from Apr 30, 2022

Conversation

jeremyevans
Copy link
Contributor

Add UploadedFile#append_to(buffer), to append to the given buffer
in chunks using readpartial with an outbuf, rewinding the tempfile
before and after (the tempfile that UploadedFile creates should
always be seekable). Switch Utils.build_file_part to use this
method.

This should result in a general decrease in memory usage for
large files, and the rewinding fixes #261.

This uses the updated spec from #268.

dervish86 and others added 3 commits April 29, 2022 14:22
Add UploadedFile#append_to(buffer), to append to the given buffer
in chunks using readpartial with an outbuf, rewinding the tempfile
before and after (the tempfile that UploadedFile creates should
always be seekable).  Switch Utils.build_file_part to use this
method.

This should result in a general decrease in memory usage for
large files, and the rewinding fixes rack#261.

This uses the updated spec from rack#268.

Co-authored-by: Jeremy Evans <code@jeremyevans.net>
@ioquatix
Copy link
Member

This looks okay to me but I wonder if we should be using IO.copy_stream?

@jeremyevans
Copy link
Contributor Author

This looks okay to me but I wonder if we should be using IO.copy_stream?

We aren't copying from an IO to an IO, or I would have used that. I don't think IO.copy_stream support copying from an IO and appending to a string, it treats a string given as a filename, according to the documentation.

Copy link
Member

@ioquatix ioquatix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay makes sense.

@jeremyevans jeremyevans merged commit 19c1eab into rack:main Apr 30, 2022
@perlun
Copy link
Contributor

perlun commented Apr 30, 2022

@jeremyevans As for the "pointless cop demands" comment, I think it's fine by me to tweak the Rubcop config (or even disable Rubocop altogether for the project) as you see fit. 👍

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

Successfully merging this pull request may close these issues.

Multipart file upload test broken
4 participants