简体   繁体   English

如何知道请求已经下载完成?

[英]how to know request already download completed?

Is there a way to know or a report about completed request or download? 有没有办法知道或报告已完成的请求或下载? currently i only can get if a url can be request and in progress by return object json status response 200. but it not accurates to do action after that response. 当前,我只能通过返回对象json状态响应200来请求并进行处理,才能获得url,但是在响应后执行操作并不准确。 algorithm is client request a file to server. 算法是客户端向服务器请求文件。 server response with json object with property size request file. 具有json对象和属性大小请求文件的服务器响应。 then in client browser get response status and compare in local currently size download in local byte by byte with json object size property that return by server. 然后在客户端浏览器中获取响应状态,并与本地返回的本地大小进行比较,并以本地字节为单位通过服务器返回的json对象大小属性进行下载。 if byte match than do something. 如果字节匹配比做某事。

fetch('http://127.0.0.1/images/tileset.png')
  .then(function(myJson) {
    console.log(myJson);
  }); 

If you want to make sure that the two files -on internet and the local file- are the same, hashing will be better! 如果要确保Internet和本地文件这两个文件相同,则哈希会更好!

You should first return the response then console it. 您应该首先返回响应,然后对其进行控制台。

 fetch('http://127.0.0.1/images/tileset.png') .then(function(myJson) { return myJson.blob(); }).then((myJson)=>console.log(myJson.size)); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM