Justin Miller


490 Experience
4 Lessons Completed
0 Questions Solved


Posted in Sortable Drag and Drop Discussion

Just a heads up, in your Gemfile, bootstrap 4 beta no longer uses tether for tooltips, now uses popper.js which is now a dependency of the bootstrap 4 gem

Yes, mostly small files at the moment. At some point it probably make sense to have a background job create a zipped version and store that on S3, but that extra bit of complexity is on the back burner for now.

Just to close the loop on this, I'm using the zipline gem to stream dynamically generated zip files to the user. Files uploaded directly to s3 via shrine. The downloads controller either spits out a zip if a project has multiple attachments, or serves up a single file otherwise. Seems to be working well so far.

include ActionController::Streaming
include Zipline

def new
  attachments = @project.attachments.all
  if attachments.count > 1
    files = attachments.map{ |file| [file.fileupload, file.fileupload.original_filename]}
    name = @project.title.parameterize
    zipline(files, "#{name}.zip")
  elsif attachments.count == 1
    file = attachments.first
    redirect_to file.fileupload.url(download: true)
    flash[:alert] = "There are no files available to download"
    redirect_to user_project_path

Posted in Best strategy for downloading multiple files from S3

Chris, thanks for the very detailed response.

Honestly not 100% sure what my usage case will be just yet, though I estimate that it'll be mostly small files (pdfs, sketchup files, CAD/CAM files, images, etc.). So I think I may be in the realm of best being the enemy of good enough. With that in mind, I'll likely stick with option 1 for now, and then proceed to monitor performance and make adjustments as needed.

One thing that surprised me somewhat when doing research is that there isn't a whole lot out there on this topic, so perhaps its not really a big deal.

Thanks for the advice!

Posted in Best strategy for downloading multiple files from S3

Im working on a rails app where Users can create a “project”. Project, has many datafiles.
Users upload multiple files direct to Amazon S3 (im using carrierwave).

I'd like Users to have the abililty to download a Projects datafiles as a single zip file. Im trying to figure out the best strategy to implement this feature. Here are the ideas I've come up with so far:

Strategy 1:
Rails creates a zip file and streams the zip to the user. (could use something like rubyzip)

  • Pros: Should be relatively simple to implement.
  • Cons: I think that the files need to hit my server (not actually 100% sure on this) which could be bad for performance if files are big leading to a poor user experience.

Strategy 2:
A background job later re-downloads the files to my server, creates a zip and reuploads to S3. Users will then be able to download the zip directly from s3 if it exists.

  • Pros: Eliminates the need to create the zip file on the fly. Users can pull directly from S3.
  • Cons: Any change to files means the zips need to be deleted and recreated. Need to still be able to serve up files if the zip copy doesnt exist on S3.

Strategy 3:
Post processing on the AWS side to create a zip whenever a bucket changes.

  • Pros: Seems like a clean way to do it.
  • Cons: No idea how to actually implement this and the AWS documentation is pretty poor. Would need a way to have AWS inform my app after processing has been completed. (something similar to a stripe webhook?)

Strategy 4:
Limit users to a single file upload per project, forcing the end users to zip their files.

  • Pros: Simplest to implement
  • Cons: Worst user experience.

I'd love to hear some input on how you'd go about this, or any resources for someone that has done something similar.

Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more.

© 2024 GoRails, LLC. All rights reserved.