Ask Question Forum:
Model Library:2025-02-08:A.I. model is online auto reply
C
O
M
P
U
T
E
R
2
8
Show
#
ASK
RECENT
←
- Underline
- Bold
- Italic
- Indent
- Step
- Bullet
- Quote
- Cut
- Copy
- Paste
- Table
- Spelling
- Find & Replace
- Undo
- Redo
- Link
- Attach
- Clear
- Code
Below area will not be traslated by Google,you can input code or other languages
Hint:If find spelling error, You need to correct it,1 by 1 or ignore it (code area won't be checked).
X-position of the mouse cursor
Y-position of the mouse cursor
Y-position of the mouse cursor
Testcursor
caretPos
Attachment:===
Asked by Wilson Edwards
at 2024-08-27 19:05:39
Point:500 Replies:2 POST_ID:829243USER_ID:12108
Topic:
javascript;file object;html
I would like my editor has function in which user can upload their files on widow 11 converted to be href DataUrl link .
I try this not work:
- if (file.type.indexOf("text") == 0) {
- var reader = new FileReader();
- var charset='charset=utf-8;base64,';
- reader.onload = function(e) {
- var href=''data:"+charset+btoa(e.target.result);
- var html_str=""+file.name+"";
- }
- reader.readAsText(file);
- }
when I click the a href link, on window, it won't download the file, only text file can work
how about make excel, xls format file, work also ?
Any easy suggestion ?
Please advise
Regards
Author: Wilson Edwards replied at 2024-08-27 19:16:34
And, other type file format also work, u can try it, for exmaple PDF file
Accepted Solution
Expert: D Ft replied at 2024-08-27 19:12:07
500 points Excellent
read this linkhttps://stackoverflow.com/questions/26322685/convert-any-type-of-file-into-base64-using-javascript-if-we-have-url-of-the-file
Probably use...
reader.onload =function(e){
var href=e.target.result //which already include data:....., everything
var html_str="<a href="+href+">"+file.name+"</a>";
}
reader.readAsDataURL(file) ///not readAsDataText
Hope it can help