当前位置: 动力学知识库 > 问答 > 编程问答 >

Download zip file from rails 4 to angularjs

问题描述:

I'm trying to download a zip file, sent from a rails 4 application to the front-end.

The zip file construction is working correctly, I can unzip the file and get the content

filename = "cvs_job_#{params[:job_id]}.zip"

archive_path ="#{Rails.root}/tmp/#{filename}"

File.delete(archive_path) if File.exists?(archive_path)

Zip::File.open(archive_path, Zip::File::CREATE) do |zipfile|

params[:user_ids].each do |user_id|

user = User.find(user_id)

zipfile.add("#{user.last_name}_#{user.first_name}.pdf", user.cv_file.path) unless user.cv_file.nil?

end

end

send_file("#{Rails.root}/tmp/#{filename}", :type => 'application/zip', :disposition => 'attachment')

but how am I supposed to handle the response back in the promise?

 $http(req).success(function(success){

console.log(success)

})

I saw the zip file in the chrome console, such as :

"...8f�~��/g6�I�-v��=� ..."

I have tried many solutions but none are working.

I thought that I would be able to send the file and download from my front.

分享给朋友:
您可能感兴趣的文章:
随机阅读: