|only for RuBoard|
IN THIS CHAPTER
Uploading Files Using HtmlInputFile
Using the HttpPostedFile
Working with the In Memory File ”Saving it to a Database
Retrieving and Showing an Image from a Database
This chapter is dedicated to the saving and displaying of database-stored binary files known as BLOBs (Binary Large Objects) in your ASP.NET Web applications. I will be discussing how to easily enable file uploading using ASP.NET and how to manipulate the file attributes after it has been uploaded to the server. Then I will discuss how to save an uploaded image directly into your database without ever saving the image to hard disk. Finally, I will demonstrate an easy way to display images derived from a database in your Web application. I will be going over the following in this chapter:
Using the HtmlInputFile class to upload files to gain programmatic access to the uploaded file
Using the HttpPostedFile class to manipulate and extract information from the uploaded file
Saving uploaded images to your database
Displaying images derived from a database
Saving BLOBS in a database has advantages and disadvantages and you have to weigh both when designing your web application. The following two lists contains some pros and cons of saving Binary Large Object Bitmaps in your database:
All information is stored in one place. For example, if you have a member table which contains a memberid, membername, address, and a picture of the member. If the user cancelled their membership it would be easier to delete one row from the table than to delete the row and then an image file(s) that could be on an entirely different server.
Updating information can be made in one centralized location.
Retrieving information can be done in one centralized location.
Accidental changes to the file system on your servers where images are located won't break links. For instance, a system administrator inadvertently changes the name of an image directory.
In most cases files will load more quickly from the hard drive.
Higher memory requirement.
All pages that contain these images need to be server pages and dynamically generated. Note: Once created they can be cached.
Bloats database ”BLOB fields such as an Image is very large.
Just because there are more pros than cons in the preceding lists doesn't mean you should automatically store images in your database. Quite the contrary; it always falls back on the question, "What type of application am I building?" Sometimes using BLOBS makes sense with the architecture of the application you're building and other times it makes no sense at all. The preceding lists are just some things to think about.
|only for RuBoard|