admin管理员组文章数量:1317739
i have html form with ENCTYPE="multipart/form-data" .It just contains the textbox of type 'file' which browses the file from local box.Here is the textbox code snippet
<td>
<input name="fileNameAttr" id="filePath" size="52" type="file" value="">
</td>
I browse the file some image file from local box. The moment i select the file, filePath gets populated in text box. Now on click of some button, i want to convert the image in to base64 String in javascript. I am not using HTML5. Can i achieve it in javascript?
i can see some solution on net using HTML5 but that does not solve my purpose. If i need to use some third party utility , i can do that.
EDIT:- looks like jquery can help with $.base64.encode( "this is a test" ); but how to use it with type="file"?
i have html form with ENCTYPE="multipart/form-data" .It just contains the textbox of type 'file' which browses the file from local box.Here is the textbox code snippet
<td>
<input name="fileNameAttr" id="filePath" size="52" type="file" value="">
</td>
I browse the file some image file from local box. The moment i select the file, filePath gets populated in text box. Now on click of some button, i want to convert the image in to base64 String in javascript. I am not using HTML5. Can i achieve it in javascript?
i can see some solution on net using HTML5 but that does not solve my purpose. If i need to use some third party utility , i can do that.
EDIT:- looks like jquery can help with $.base64.encode( "this is a test" ); but how to use it with type="file"?
Share Improve this question edited Oct 23, 2012 at 15:46 M Sach asked Oct 23, 2012 at 15:40 M SachM Sach 34.4k78 gold badges230 silver badges317 bronze badges 4- possible duplicate of Convert image to base64 javascript on firefox – Diodeus - James MacFarlane Commented Oct 23, 2012 at 15:42
- @Diodeus he wants a non HTML5 way – Bob Fincheimer Commented Oct 23, 2012 at 15:45
- @RASG that does encoding on strings, not on a local image – Bob Fincheimer Commented Oct 23, 2012 at 15:46
- You may be able to do it with flash: stackoverflow./questions/1243912/read-local-file-in-flash – gcochard Commented Oct 23, 2012 at 17:00
2 Answers
Reset to default 3this can be done by the HTML5 <canvas>
for it
or
if you have node.js as an option then try something like that in img
or <img src="data:image/png;base64,jkasfhsdjkhsadf" />
example
var fs = require('fs');
var base64_data = new Buffer(fs.readFileSync('sample.png')).toString('base64');
console.log('<img alt="sample" src="data:image/png;base64,' + base64_data + '">');
check this (also source of example)
Data URI scheme
Good read
- How can you encode to Base64 using Javascript? //its for image
If you could access the local filesystem via javascript, what would keep you from reading the password file or other private data?
This you can't do and it can't and won't be allowed in the future, for obvious reasons!
本文标签: htmlConverting the image in base64 string in javascriptStack Overflow
版权声明:本文标题:html - Converting the image in base64 string in javascript? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742020173a2414457.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论