文件下载完成后,我们可以知道任何事件/方式吗? [英] Is there any event/way we can know when a file has finished downloading?
问题描述
这个问题已被问了很长时间,但我无法得到完美的答案。所以我再试一次。
假设您希望在文件从服务器上完全下载后显示一条消息。是的,有可能上传文件的方法,甚至在下载时显示进度条,但有没有特定的实例/信息/事件可以告诉下载何时完成?
我所知道的可能是它可以在cookie的帮助下实现。但是如何?
当您从服务器请求文件时,请从客户端向下载服务发送唯一密钥。 / p>
获取/下载?fileId = someId& cookieName = abc
服务器时已完成提供文件内容,设置一个具有唯一名称的cookie
var cookieName = Request.QueryString [cookieName];
Response.Cookies.Add(new HttpCookie(cookieName,true)
{
Path =/,
HttpOnly = false
});
同时,在你的JavaScript中,听一个带有你唯一名字的cookie,一旦设置好,做一个回调:
window.setInterval(function(){
var cookie = $ .cookie('abc ');
if(cookie!== null){
callback();
}
},500);
您可能还想在完成后删除cookie。
This question has been asked a much time, but I am unable to get a perfect answer to implement. So I give it a try asking one more time.
Suppose you wish to show a message when your file has be completely downloaded from the server. Yes, there are possible ways for uploading a file, and even showing a progress bar on download, but is there any particular instance/information/event which should tell when the download has been completed?
All I yet know is that might be it can be implemented with the help of cookies may be. But how?
When you request a file from your server, send a unique key to the download service from the client.
GET /Download?fileId=someId&cookieName=abc
When the server has finished serving the file contents, set a cookie with the unique name
var cookieName = Request.QueryString["cookieName"];
Response.Cookies.Add(new HttpCookie(cookieName , "true")
{
Path = "/",
HttpOnly = false
});
Meanwhile, in your JavaScript, listen for a cookie with your unique name on it and once it is set, do a callback:
window.setInterval(function () {
var cookie = $.cookie('abc');
if (cookie !== null) {
callback();
}
}, 500);
You might also want to look into deleting the cookie when you are done.
这篇关于文件下载完成后,我们可以知道任何事件/方式吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!