Closed abitdodgy closed 8 years ago
it could probably be MADE to work. The easiest way would be to wrap up the Refile with some sort of stream object.
a quick look at refile makes me think you could call Refile::File#to_io and pass that in somehow.
Yes, indeed. That does the trick. Assuming you have a Document
model that accepts attachment :file
, you can do this:
def download
folder_name = Time.zone.now.to_i
files = @documents.map do |document|
[document.file.to_io, "#{folder_name}/#{document.file_filename}"]
end
zipline files, "#{folder_name}.zip"
end
This assumes Refile's backend is not sitting behind a CDN. I've not tested how that would work. I'm also not sure how that would play with zipline and zipping files from a remote URL. I'll do some more tests here.
cool, thanks. also if to_io starts an http request, you probably want to use a lazy map.
On Fri, Aug 28, 2015 at 12:55 PM Mohamad El-Husseini < notifications@github.com> wrote:
Yes, indeed. That does the trick. Assuming you have a Document model that accepts attachment :file, you can do this:
def download folder_name = Time.zone.now.to_i files = @documents.map do |document| [document.file.to_io, "#{folder_name}/#{document.file_filename}"] end zipline files, "#{folder_name}.zip"end
This assumes Refile's backend is not sitting behind a CDN. I've not tested how that would work. I'm also not sure how that would play with zipline and zipping files from a remote URL. I'll do some more tests here.
— Reply to this email directly or view it on GitHub https://github.com/fringd/zipline/issues/18#issuecomment-135831572.
Yeah, I'm noticing that the file is only downloaded after it's been fully created. I'm assuming because .to_io
is actually downloading the files.
@fringd what would that look like? Something like this? Doesn't seem to matter...
files = @documents.lazy.map do |document|
[document.file.to_io, "#{folder_name}/#{document.file_filename}"]
end
yeah, although maybe even this won't be enough... maybe you'll need to get the url yourself and pass in an object that responds to url...
I'm curious, sorry to beat this issue to death, but how do you handle form submissions? The response is streamed back to the browser and the request never does anything to the page. So page state is maintained. If you have a form with checkboxes, the window remains in its current state, check boxes checked, and all. I can trigger a page refresh with Javascript, but there's a way to do this after the file has finished downloading. In my browser, for example, when the form is submitted, the page refreshes, and goes back to its normal state, then later the file arrives after its files have finished downloading from S3. This means I can't give any feedback to the user that their file is being prepared... :disappointed:
Can you think of a way to get around this?
if it's downloading the whole file from s3 before the user sees progress then something is not working somewhere. Either streaming is not set up properly on your server, or maybe this was before you had lazy set up, or maybe it's because .to_io is taking a long time on the first file. (in which case the url thing i mentioned might be needed.)
I'm not sure what you mean about forms.
Refile works differently to CarrierWave and Paperclip. All requests go through a rack app, which does the work of retrieving S3 files. It also does on the fly processing. Would zipline work with Refile?