views:

167

answers:

2

I need to upload an image and then preview it without posting back as i need to have a file upload control(even HTMLinputfile or ASPfileupload) then the user will browse to select image after selecting (browsing) there will a button(HTMLInputButton) that will save the uploaded image and preview it.

I have the following code :

<div>
    <input id="UploadInput" type="file" value="Upload" />
    <br />
    <input id="PreviewBtnInput" type="button" value="Preview" onclick="ShowPreview()" /> 
    <br />
    <img id="ImgUploaded"  />
</div>

So how can i do this task ?

Thanks in advance for any reply but please if any one has a link for article that talk about this issue please i need a clear code not article details.

A: 

In order to preview images before uploading them to the server you'll need to use a Flash-, Silverlight-, ActiveX-, or Java Applet-based file uploader. The file input itself doesn't allow you to interact with the actual file and display it in your web page. Using it alone would require you to upload the file to the server, where you can then refer to it using a URL (either directly as a file or via an HTTPHandler). If you must have preview before post, you should look for an existing product that will handle this on the client side for you. A quick google for flash-based file upload, brought up this, this, and this in the results.

tvanfosson
I dont need flash control or silverlight i need to upload the image or have a preview of the image selected withou posting back i just need to show the image selected by the user before submitting the form and there is no need for flsh or any external resoureces i just want to know how can i upload the image or previewing it even with inputfile or fileupload i need it without posting back may call webservice or use ajax concepts but no need for external resources.
Ahmy
@Ahmy - AJAX calls are posting back to the server and won't work for file upload anyway. You could use an iframe to postback to the server and keep the user on the same page, but you'd still have to do a postback -- just in the iframe. If you want to do real client-side preview, you don't have a choice but to use a plugin.
tvanfosson
@tvanfosson - Your answer seems to be logically but the plugins is too complicated and i need an explicit code to handle this process without more complication that i found in this plugins at all i think that iframe may be suitable i will try it but will all the page postback or just the iframe portion? i need to know will the progress bar of loading will appear or not? and thanks for your answer
Ahmy
@Ahmy - You can make it so that only the iframe posts back, but I believe that you will get page loading progress indicator.
tvanfosson
+1  A: 

You can use the project mentioned below to preview the image before uploading. Working sample is also attached.

http://www.dotnetspider.com/resources/40858-Preview-Image-before-uploading-using.aspx

This uses AjaxControlToolKit's AsyncFileUploadControl and HTTPHandler to upload the image.

dhinesh