1

I need to preview an image using javascript before upload to provide a crop facility. For this purpose, I create an Image object in javascript.

var image = new Image();

To confine big images to a limited space, I access the height and width of the image using image.width and image.height

For some of the images, I find that this value is shown as zero and for which when I inspected the image object, found that image.mimeType has the value Unspecified Error (Even the file creationdate shows unspecified error).

As such I am not able to preview those images. How do I solve the problem?

1 Answer 1

4

You won't be able to get a preview of image from the client system. You have to upload the image to a server and can show the image preview from there.

Reading files from the client system is a security threat and most browsers won't allow that. In earlier versions of IE you can get that, but won't be available in newer versions and other browsers.

Sign up to request clarification or add additional context in comments.

3 Comments

"You won't be able to get a preview of image from the client system" ?? I am able to do this for some of the images where the mimetype is not unspecified error?? How will you justify
@Ajay I can't explain why you are able to read some images from the client system. Normally that is not supposed to happen.. imagine: opening a webpage that reads your hard disks and steals private data!
inorder to upload the file, your webpage has to read the local image file rite? that is what is happening here as well??

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.