TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Ajay Gupta
NA
330
59.2k
Download selected file as preview option using Jquery
Sep 10 2018 1:33 AM
In my case the user can select a file and click on the submit button. after submitting button I am showing the file as table format with file name, file size, download link and remove option. now my requirement is if user click on the download button from the table then the file should download. I don't want to upload file server side on a selection of files .
var
file = document.getElementById(
'documentfile'
).files[0];
var
filename = document.getElementById(
'documentfile'
).files[0].name;
var
size = document.getElementById(
'documentfile'
).files[0].size;
var
ext = $(
'#documentfile'
).val().split(
'.'
).pop().toLowerCase();
var
reader =
new
FileReader();
var
fileurl;
reader.onload =
function
(e) {
fileurl = e.target.result;
}
reader.readAsDataURL(file);
var
str =
'<tr><td>1</td><td>'
+ filename +
'</td><td>'
+ $(
'.sltdoctype'
).val() +
'</td><td>'
+ niceBytes(size) +
' </td><td> <a href='
+ fileurl +
' download>download</a></td><td> <a href="#" class="anchorRemove" >Remove</a> </td></tr>'
$(
'.document-table-str .table .tbody'
).append(str);
$(
'.document-table-str'
).show();
$(
'#documentfile'
).val(
""
)
Reply
Answers (
2
)
dehover_node.jstree
How to convert JSON response list to array in jquery