It is a tiny application about “How to upload images?”. User shall provide username, browse file from local machine and once clicks on “add” button the details are saved (database or file system). Please find the code above for your reference In the above source code you can observe that the file(image) uploaded by client is saved using a class “UserDetailsData” which is created exclusively to save or retrieve user details which is user name and relative of the uploaded image file at server. There 2 ways of uploading image file. 1) If you use data base , you create a table with column say “Image” whose data type should be BLOB (Binary Large Object). While inserting a row into this table you can insert the byte stream of the image file uploaded at this column and while retrieving you should type cast the blob data to byte[] array and save into a file whose src should be used to a img tag to display. 2) The other way in Image column which can be Varchar , you can just save the uploaded image and save to application server local disk and whose file path can be saved in this Image column. While retrieving you can read the path and assign it directly to img tag as src.
In the above example I have done it using (2) but since I am not Orcale data base server , so I used serialization concept to save user name and image file path into a data table and then writing the state of data table to a text file (Object persistence).
|
Display images using GridView control
ReplyDelete