To be more specific, I want to use a form with one or more file input fields used for images. When those fields are changed, I'd like to show a preview of the associated image, before sending the data to the server.
I've tried a number of javascript approaches, but I always run into security errors.
I wouldn't mind using java or flash, as long as the solution degraded gracefully for those users who didn't have them. (They wouldn't get previews, and they wouldn't get an annoying 'install this thing' either.)
Has anyone done this in a simple, reusable way?
P.S. I know there's a sandbox, but does the sandbox have to be in a dark, locked room with all the windows blacked out?
Best Solution
No need for fancy stuff. All you need is the
createObjectURL
function, which creates a URL that can be used as the imagesrc
, and can come straight from a local file.Let's say you selected a couple of images from the user's computer using a file input element (
<input type="file" />
). Here's how you would create previews for image files for it: