Download the weighted project, how do you do, please comment.

Project we met this demand:

  We can download directly <a download> </a> direct download, then the question is, we direct path back href assignment src return, our file can be downloaded, but now I record your static routes, but background and no time to clean vas stored files, then after we recorded directly address bar splicing is not it also be downloaded directly, even if what you have to log case.

  This issue still sounds pretty simple, but have to deal with on our front and back office processing, background processing documents need regular, front-end to do is log in to add to the file permissions, so we thought of token login token.


Then we step by step:

  1, to download the file can not be downloaded to this way, we need to request interface to download the file.

  2, nginx need permission token to download the configuration file path, and take them to redis logged in, if found in default so you can download.

   getDownFile = const (href, _name, of the type) => {IF return; (href || _name!!)    !! of the type console.log ( "Current file path:", href): NU?    the let = new new xhr the XMLHttpRequest () ;

 xhr.open("get", href); xhr.setRequestHeader("accessToken", "登录之后存入token的前端缓存中取"); xhr.setRequesHeader("Accepet", "*/*"); xhr.responeseType = "blob"; xhr.onload = function() { if(this.status != 200) return;  let blob = this.response; // 进行文件的生成 let a = document.createElement('a'); let url = window.URL ? window.URL.createObjectURL(blob):window.webkitURL.createObjectURL(blob); a.href = url; a.down = `file.${_name}`;
document.body.appendChild(a);
     a.click();
   window.URL.revokeObject.URL(url);// Clear the URL of }
}

  At this time the tip is do these, these things we can get added to the interface token, if we do not sign in, the page is no way to directly download files. Want to help your project, you want your thumbs, and comment. . .

Guess you like

Origin www.cnblogs.com/GongYaLei/p/11349670.html