Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old July 3rd, 2007, 09:22 AM
Registered User
Join Date: Jul 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to Encode image to base64?

I need to encode an image in the user harddrive to base64, so that I can send it back to the server as a string in a hidden input field.

Does anyone has a script to encode an image into a base64 string? or can tell me how to do it please?

Thanks in advance.

Old July 3rd, 2007, 12:04 PM
Friend of Wrox
Join Date: Dec 2003
Posts: 488
Thanks: 0
Thanked 3 Times in 3 Posts

*nixes have uuencode and uudecode. But if I were you I'd look at the "file" input type. There's a tute at: http://www.cs.tut.fi/~jkorpela/forms/file.html . This will do the job much better, with less processing needed and more cleanly. And it means writing less code. Which is always good ;)

Charlie Harvey's website - linux, perl, java, anarchism and punk rock: http://charlieharvey.org.uk
Old July 3rd, 2007, 11:13 PM
Authorized User
Join Date: Jun 2007
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts

Hi OniShirox

In order to encode a file in client side, you should first open it using javascript, and this would not be possible (due to security restriction) unless you use an ActiveX like FileSystemObject, and it works only on IE.

After opening file by ActiveX, you can read it's content and do anything you want and finaly store it in a hidden text field to be send to client.

Ehsan Zaery Moghaddam
Old July 5th, 2007, 02:12 AM
Registered User
Join Date: Jul 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts

Can someone post some example please?

It's ok if it only works on windows/IE.


Old July 5th, 2007, 03:10 AM
joefawcett's Avatar
Wrox Author
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts



Joe (Microsoft MVP - XML)

Similar Threads
Thread Thread Starter Forum Replies Last Post
Decoding Base64 Encoded Data and saving the image mookashi XML 14 August 3rd, 2006 05:52 PM
Base64-encoded files harpua Classic ASP Professional 2 June 19th, 2006 12:04 PM
PNG image in base64 encoding janise PHP How-To 4 April 20th, 2006 02:30 PM
base64_encode() to encode image data vibinkrish Beginning PHP 1 March 9th, 2006 11:27 AM
Image Upload to base64 format laker66 ASP.NET 1.0 and 1.1 Basics 1 April 8th, 2004 12:35 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.