Web 如何从移动网络下载文件?

Web 如何从移动网络下载文件?,web,mobile,download,Web,Mobile,Download,我可以下载文件。 该代码在PC网络浏览器上运行良好,但在移动网络浏览器上不起作用。如果您知道它在手机上的工作原理,我将不胜感激 const filePath = findFile[0].path; const fileName = findFile[0].filename; const mimetype = mime.getType(filePath); // Header setting res.setHeader('fileName', encodeURIComponent(fileName

我可以下载文件。 该代码在PC网络浏览器上运行良好,但在移动网络浏览器上不起作用。如果您知道它在手机上的工作原理,我将不胜感激

const filePath = findFile[0].path;
const fileName = findFile[0].filename;
const mimetype = mime.getType(filePath);
// Header setting
res.setHeader('fileName', encodeURIComponent(fileName));
res.setHeader('Content-type', mimetype);
res.setHeader('Content-Disposition', 'attachment; filename=' + encodeURIComponent(fileName));
// aws s3 file
const params = {
    Bucket: 'flag-kog',
    Key: `${username}/${fileName}`
};
s3.getObject(params)
    .createReadStream()
    .pipe(res);
componentDidMount(){
常数{
用户名,
旗名
}=this.props.match.params;
axios({
url:`/api/files/download/${username}/${flagname}`,
方法:“GET”,
responseType:'blob',
})
。然后(res=>{
const filename=decodeURIComponent(res.headers.filename);
这是我的国家({
文件名,
});
//下载
constURL=window.url.createObjectURL(新Blob([res.data]);
const link=document.createElement('a');
link.href=url;
link.setAttribute('下载',文件名);
document.body.appendChild(链接);
link.click();
这是我的国家({
下载:对,,
});
})
.catch(()=>
这是我的国家({
呃:是的,
})
);
}

再试一次!!它起作用了

•例如: 如果您想在上下载图像或文件,请单击“下载”链接

(通过onClick阻止jquery)

HTML代码:输入代码的位置。

<a><img src="XYZ" /></a>
<p>file name</p>
<a href="XYZ" @click.prevent="_downloadImg('{{downLoad}}','file name')">Download</a>
_downloadImg(src,alt){      
    var url = src;
    var fileName = alt;     
    var xhr = new XMLHttpRequest();
    xhr.open("GET", url, true);
    xhr.responseType = "blob";
    xhr.onload = function(){
        var urlCreator = window.URL || window.webkitURL;
        var imageUrl = urlCreator.createObjectURL(this.response);
        var tag = document.createElement('a');
        tag.href = imageUrl;
        tag.download = fileName;
        document.body.appendChild(tag);
        tag.click();
        document.body.removeChild(tag);          
    }
    xhr.send();
}