使用Paperclip下载文件 [英] Download file using Paperclip

查看:212
本文介绍了使用Paperclip下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,这可能是重复的问题,但由于时间限制,我无法搜索。我想下载一个使用纸夹上传的文件。我的下载代码如下:

  def download_digital 
@photo = Photo.find(params [:photo])
send_file @ photo.image.path,
filename:@ photo.image_file_name,
type:@ photo.image_content_type,
disposition:'attachment',
x_sendfile: true

puts----------- Downloded ----------
end

当这个被调用时,我得到

 已发送文件/Users/c193/Documents/***/***/***/public/assets/photos/298/original/Wedding_2.jpeg(0.1ms)
--------- - 已下载----------

这样就清楚了文件是获得。但是,该文件未被实际下载。我不知道我失踪了我是一个新手,所以任何指导将是有帮助的。



P.S:另外对于重复的问题感到抱歉(万一;时间限制,不知道要搜索的内容)。谢谢你提前。

解决方案

我不知道是否发现问题是实际是问题,但到目前为止,我得出的结论是,使用ajax是一个问题。在控制台我得到的文件是下载,但实际上并没有下载。我正在发布一个新的问题。如果有人对此类行为有解释,请发表评论。 Thanx:)


Firstly, this might be duplicate question but due to time limitation, i couldn't search throughly. I wish to download a file that was uploaded using paperclip. My code to download is below:

def download_digital
    @photo = Photo.find(params[:photo])
    send_file @photo.image.path,
              filename: @photo.image_file_name,
              type: @photo.image_content_type,
              disposition: 'attachment',
              x_sendfile: true

    puts "-----------Downloded----------"
  end

When this is called, i get

Sent file /Users/c193/Documents/***/***/***/public/assets/photos/298/original/Wedding_2.jpeg (0.1ms)
-----------Downloaded----------

This makes it clear that the file is obtained. However, the file is not being actually downloaded. I dont know what i'm missing. I'm a newbie so any guidance will be helpful .

P.S: Also sorry for a duplicate question (in case; time limitation and no clue what to search). Thank You in advance.

解决方案

I don't know if what is found the problem was actually is the problem but so far i have come to the conclusion that the use of ajax was what was creating an issue. In the console i got that the file is downloaded but it was not actually getting downloaded. I am posting a new question for the same. If anyone has an explanation for such behaviour, please post a comment regarding this. Thanx :)

这篇关于使用Paperclip下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆