I'm trying to make a request to a Rails controller method that responds with a zipped file. How to I make the frontend Axios request?
Controller method:
include ActionController::Streaming
include Zipline
def index
respond_to do |format|
format.zip do
zipline([[@project.attached.url, "#{@project_name.parameterize}.pdf"]], "documents.zip")
end
end
end
What I would do if I were using a view:
= link_to "Download projects", company_projects_path(@company, format: :zip)
What would the equivalent axios request look like? This does not work:
const handleClick = () => {
axios
.get(`/projects/${project.id}`, {
headers: { 'Accept': 'application/zip' }
})
.catch(e => console.log(e))
};