有
我对网络编程很陌生,目前正在开发一个需要从服务器下载文件的项目。我有以下代码但它运行不正常。它发送的http请求不是我期望的那个...详细信息在代码中注释。感谢
onDownload() {
const Files = this.props.files;
const file = Files.findOne({ name: this.props.selectedFile.name });
const filePath = file.fileSpec; //file path is like /test.txt
var tempLink = document.createElement('a');
// would like to send some http request like:"/user/test.txt"
//to the server. But it sent some strange string...
// I feel like I need to convert the format here but not sure how
tempLink.href = '/user' + filePath;
tempLink.setAttribute('download', file);
tempLink.setAttribute('target', '_blank');
document.body.appendChild(tempLink);
tempLink.click();
document.body.removeChild(tempLink);
}