我们可以发现,当一个回形针下载完成? [英] Can we find out when a Paperclip download is complete?

查看:128
本文介绍了我们可以发现,当一个回形针下载完成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我需要知道,当一个用户的轨道/回形针文件下载为完成的应用程序。我的应用程序设置为与Amazon S3的互动,我需要运行的JavaScript函数,当用户收到了已完成的文件。

I have an application where I need to know when a user's Rails/Paperclip file download is complete. My app is set up to interact with Amazon S3 and I need to run a javascript function when the user has received the completed file.

我怎样才能做到这一点?

How can I do this?

推荐答案

跟踪天气或不下载完成后是很难的,尤其是在Javascript。有你的问题的几个模糊的线,让我觉得它不可能。

Tracking weather or not the download completes is hard, especially in Javascript. There are a few blurred lines in your question which makes me think its not possible.

首先,由send_file 通过一个特殊的头告诉Web服务器,告诉它送什么。请参见的由send_file文档。 Rails没有实际发送的文件,同时,它设置这个头,告诉发送文件的Web服务器,但随后立即返回,并移动到另一个服务请求。为了能够跟踪如果下载完成,你必须占据你的Rails应用程序发送,而不是离开那个到Web服务器(这是它的目的是做)的文件和块,直到用户下载它。这是超级低效的。

First, send_file passes a special header to tell the webserver telling it what to send. See the send_file docs. Rails doesn't actually send the file at all, it sets this header which tells the webserver to send the file but then returns immediately, and moves on to serve another request. To be able to track if the download completes you'll have to occupy your Rails application process sending the file and block until the user downloads it, instead of leaving that to the webserver (which is what its designed to do). This is super inefficient.

接下来,你怎么能仍然是一个网页执行JavaScript函数,如果你正在下载的文件吗?你的用户点击该文件下载链接,并带到任何地方的文件是,天气是是由send_file 从导轨或重定向到S3也好,他们不再对页面他们是从哪里来的。如果你正在考虑Chrome或Firefox的工作在哪里下载进入下载管理器,用户停留在页面上的路,那里有与旧页上的服务器没有更多的互动!如果你想下载完成该页面被通知,那么你需要定期检查或长轮询服务器以查看是否下载完成。

Next, how can you still be on a page to execute a javascript function if you are downloading a file? Your user clicks the file download link and is taken to wherever the file is, weather that be a send_file from Rails or a redirect to S3 or whatever, they are no longer on the page they came from. If you are thinking about the way Chrome or Firefox works where the download goes into a download manager and the user stays on the page, theres no more interaction with the server on the old page! If you want that page to be notified of download completion, then you'd need a periodic check or long poll to the server to see if the download is done.

我想你会被重定向到S3文件和设置会话变量将用户重定向到您希望他们下载后去得到更好的服务完成,以便下一次他们访问的任何网页,他们回来了在你的计划流程。

I think you'd be better served by redirecting to the S3 file and setting a session variable to redirect the user to where you want them to go after the download is complete so that the next time they visit any page they are back in your planned flow.

希望这有助于!

这篇关于我们可以发现,当一个回形针下载完成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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