fringd / zipline

A gem that lets you stream a zip file from rails

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Zipline not executing locally

TrevorHinesley opened this issue · comments

I'm running a pretty vanilla zipline setup, but running zipline as the last function in a controller action doesn't seem to be executing anything.

Ruby 2.5.1, Rails 6.0.2, Zipline 1.2.1

It's an array of arrays, and even if I run it with the following from the controller, the endpoint executes just fine, but no download happens (assume the URL is a signed S3 url):

class DownloadController < ApplicationController
  include Zipline
  layout "authenticated"

  def download_all
    urls = [
      ["https://myfile.com/file.mp3", "filename.mp3"]
    ]
    zipline(urls, "bulk_download_#{Time.current.to_i}.zip")
  end
end

I'm using Puma, but is there something else I'm missing?

If I pass a fake URL, it still completes the request. It seems like something's not firing properly.

EDIT: Passing a fake URL throws an error (Read error: #<ArgumentError: Bad File/Stream>); I was mistaken. So it's executing, but nothing happens in the browser and the request looks complete in the console logs.

Passing a fake URL throws an error (Read error: #<ArgumentError: Bad File/Stream>); I was mistaken. So it's executing, but nothing happens in the browser and the request looks complete in the console logs.

Ahh figured it out. Has something to do with it being done via an XHR/AJAX POST. Does it need to have a particular Accept header to work properly? Not sure why AJAX would matter unless that has streaming restrictions of some kind.

Might be due to download limitations of AJAX itself: https://stackoverflow.com/a/9970672

you can't do it through Ajax because JavaScript cannot save files directly to a user's computer (out of security concerns)

Workaround was creating a form with Javascript, appending it to the page, and POSTing that.