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

Fix #1780 (Fog based file upload streaming) #2303

Closed
wants to merge 2 commits into from

Conversation

DarkArc
Copy link

@DarkArc DarkArc commented Apr 12, 2018

What this is about

This fixes an issue with file upload streaming. Previously passing the file was added in PR #468, and was subsequently broken by PR #1517.

This corrects the approach implemented in PR #468, without introducing the problem in PR #1517.

Approaches

I came up with three different approach for file upload:

Approach A

We could read the file into memory as carrierwave currently does. This results in large files often exhausting the heap space of the process, thus making carrierwave a poor choice for large file uploads.

Approach B

We could set a flag to mark a stream uploaded file as needing retrieved. This would result in an additional retrieval requests carrierwave does not currently make, potentially costing in bandwidth for users making use of the current code.

Approach C

We could store a reference to the source file, and then use that for reading. This would result in issues reading the uploaded file content if the source file is a temp file that goes out of scope.

Chosen approach

I ended up using Approach B, as I think it's the least buggy/best for most people. However, I'm open to feedback, my first commit in this PR is Approach C, however, the second commit changes it back to Approach B.

I wanted to open up a pull request to see what the general carrierwave community thought was the best approach to fix streaming support.

This fixes an issue with file upload streaming. Previously passing the file was added in PR carrierwaveuploader#468, and was subsequently broken by PR carrierwaveuploader#1517.

This corrects the approach implemented in PR carrierwaveuploader#468, without introducing the problem in PR carrierwaveuploader#1517.

New behavior:

  In the case of a fog based retrieval request, the file will be fetched as it was previously. The file read method will then see that file.body is set to a non-nil value, and return the file content from the file object.

  In the case of a fog based storage request, the file will be uploaded either as full text, or in batches as it was in PR carrierwaveuploader#468. However, to address the issue observed in PR carrierwaveuploader#1517 we set the body to nil, and then store a reference to the source file (the CarrierWave::SanitizedFile/read compatible object passed). This in turn results in the read method seeing no body on the file object, and consulting the source file for the file contents.

The approach to storage requests is taken over two other approaches:

  Approach carrierwaveuploader#1:

    We could read the file into memory as carrierwave currently does, however, this results in large files often exhausting the heap space of the process, thus making carrierwave a poor choice for large file uploads.

  Approach carrierwaveuploader#2:

    We could not store a reference to the original source file, however, this would result in an additional retrieval requests carrierwave does not currently make, potentially costing in bandwidth for current users.
…the original approach where read still wouldn't work if the referenced file went out of scope (ex, the temp file used for uploading is closed)
@mshibuya
Copy link
Member

#2314 have been merged instead.

@mshibuya mshibuya closed this Jun 30, 2018
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.

2 participants