there
I am pretty new to web programing and currently working on a project which needs to download the file from server. And I have the following code but it is not working well. The http request it sent is not the one I expected... Details commented in the code. Thanks
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);
}