I am creating a web app in which I want my user to download the file which they are selected in input type="file"
here is my html
<input type='file' id='fieldID' onchange="return ValidateFileUpload('fieldID')"/>
now my JS
function ValidateFileUpload(ID) {
var fuData = $('#' + ID);
var FileUploadPath = fuData[0].value;
//To check if user upload any file
if (FileUploadPath == '') {
} else {
var Extension = FileUploadPath.substring(
FileUploadPath.lastIndexOf('.') + 1).toLowerCase();
//The file uploaded is an image
if (Extension == "gif" || Extension == "png" || Extension == "bmp"
|| Extension == "jpeg" || Extension == "jpg" || Extension == "pdf" || Extension == "ppt" || Extension == "pptx" || Extension == "doc" ||Extension == "docx"
|| Extension == "xls" || Extension == "xlsx") {
var file = $('#' + ID)[0].files[0];
var filename = $('#' + ID)[0].files[0].name;
var blob = new Blob([file]);
var url = URL.createObjectURL(blob);
$(this).attr({ 'download': FileUploadPath, 'href': url });
filename = "";
}
//The file upload is NOT an image
else {
alert("Document is not the correct format: pdf,ppt,pptx,doc,docx,xls,xlsx and txt are the only document types allowed for upload. Please try again.");
}
}
}
but I am not able to download the selected file, can you please help me out to download the file selected in file upload