Im developing art gallery which needs 1000s of images to be uploaded so inserting images in DB won't be feasible. so i want to give link of folder inside db where ultimately images should get stored. plz help.
so inserting images in DB won't be
feasible
Why? Works very nicely. Especially with 2008 where you then dump them into a file system store again transparently.
I have a datas store where I store about 500gb of binary information all stored within the database. No issue at all.
Actually if you are using SQL 2008 you can use the FileStream mechanism, which actually stores the images as files on disk, but can be returned in sql results, so the data is still relational.
But answer aside, there's nothing wrong with storing 1000's of images in the database. But worst case, just store the string link if you really want.. its just that process is a little archaic.
It all depends on the DB that you're using I suppose (you didn't mentioned which you're using)
You can always store a relative path to the image file.
For example you might store images at UNC location of: \\YOUR_SERVER\myApplication\images\image1.png
-> the relative path would just be \myApplication\images\image1.png
(By storing just the relative path to the file, you're isolating the possiblity that you might change the server location in future.)
If you are using Sql Server 2008, then checkout the FileStream feature. More background info here.
One of my sites stores all user uploaded images in sql server and it works great. The only problem I can see if you are using shared hosting where you don't get a large database. Otherwise I think its a great option.
Related
What would be the better Idea to store Images ? Is it Database (or) any hosting ?
(or) Is there any other idea to store images using ASP.net.
The standard answer is to use both; database holds the location of the files and the file server holds the actual data.
The main advantages of doing this are listed in Store pictures as files or in the database for a web app?
If you are using SQL Server and version 2008 or higher then its worth to store image in file stream. It contains both advantage of storing image in files and database.
Here you can find more information about it from following links.
http://technet.microsoft.com/en-us/library/bb933993(v=sql.105).aspx
http://www.codeproject.com/Articles/128657/How-Do-I-Use-SQL-File-Stream
Regards,
i'm asp.net beginner and currently working in "upload download file" project with asp.net and vb.net as code behind language (like skydrive's web).
what i'm want ask is about upload file in server, must we store path file, size, accessed or created date into database? as we know we can use directory listing in system.io.
Thanks for your help.
You definetly want to store the path of the file. You want a way to find the file ;) Maybe later you will have multiple servers, replication or other fancy things.
For the rest, it depends a bit on the type of website. If it's going to get high traffic then store it in the database, this will limit the number of IO call (very slow). Also, it'll be a lot easier to handle sorting and queries. (sort by date, pull only the read onyl files, ...).
Database will also help if you want to show history or statistique.
You can save file in some directory and can save path of that file in database. You can also store size and created date of that file in DB. But storing a file in DB is a bit difficult. Rather than save file in Directory and save path of that file in DB
you could store the file information in a database to built some extra features like "avoid storing duplicate files", because you are having a faster search in the database! if you search the filesystem always a recursive function call get started
I have visual studio 2010 with sql express. Im trying to create a asp website that will display a file from a database, and need to insert a textfile or pdf into the database table, can this be done using the visual interface, all the intructions i have found is only using the sql insert command?
Thanks
No you can't do this. Basic UI interface means you can type it in, you can't type in an array of byte.
So that means code, it's not hard, but I would recommend you consider storing the a url / filename in the table and then putting the file on the file system instead of as a blob in the table.
Files in database blobs does have some benefits for local deployment, in that you don't have to worry about some muppet making them inaccessible. Server side though that is far less of a worry. As long as you back up database and file system and come up with a reasonable directory and file naming structure its much less of a cost than bloating a database with a load of stuff you can't use in a query, not to mention it tends to make a fair mess of volume (mdb) file.
Oh and there are persistant rumours that MS are going to drop blobs over 8000 bytes as well.
I am a novice when it comes to websites
i'm developing a website for a real estate company this site will have loads of pictures of houses for sale
i thought of storing the images in a database but i have been advised to use a folder instead
which would be the best method to use a database or folder considering that there will be images added to the site on a daily basis ?
thanks
It's best performance wise to use the filesystem, and safety-management wise it's better to use the DB (backups and consistency).
However, in SQL Server 2008, you can apply the FILESTREAM attribute to a varbinary column, and SQL Server then stores the data for that column on the local NTFS file system.
Read about FILESTREAM Storage in SQL Server 2008
Also refer to the following:
FILESTREAM Overview
Getting Traction with SQL Server 2008 Filestream
Personally I would add the images into the file system as adding them to a database will bloat the database and not give you any advantages over the file system.
When storing them in the file system, you can create folders based on a unique id linked to the record in the database. This then means that you can add any media types to this folder and then recall/display them based on the unique id. It also means that you can display multiple images by simply coding your system to display all images in the folder.
Also, look into a content delivery network (CDN) which will cache the images and give you better performance when it comes to loading speed.
Don't put them in a database, this is highly ill advised for performance reasons.
Store them in a folder, and store the location to the image in the database.
Store them in a folder. If you have lots of images, a strategy to create subfolders (id, hash, uuid, etc) will be helpful.
imagefolder
+--00
| +--00
| +--01
| ...
| +--FF
+--01
+--02
I have a .jpg file which represents the current image from a webcam. User's will be downloading this file at an interval of once a second. Because there could be dozens of users reading it, this could be dozens of times a second (which is normal for any web server).
Problem is, this image is updated by a 3rd party application also once a second which "spiders" my local networks webcam portal image. This is so we can build our webcams into our current administration panel.
The problem I am already finding is ASP.net sometimes gets an error it can not access the file because it is open for write permissions by the bot. Likewise, the bot can not access it because IIS is feeding it to the user.
The bot uses io.streamwriter to save the data to the file, and my script uses Response.WriteFile to send the file to the script. (I need to use an actual ASP.net page with a JPG content-type that feeds the file to make sure only users with a active session can view the JPG).
My question is what is the best practices for this? I know why it's happening but what is the best resolution for this? Would storing as a BLOB in a database maybe be smarter since databases are created for concurrent read/writing already? Is there an easier way of doing this with a file I have not thought of yet?
Thanks in advance,
Anthony Greco
Using a BLOB will work if the readers use SNAPSHOT isolation model (SQL Server 2005 and up). See Download and Upload images from SQL Server via ASP.Net MVC for how to stream an image from a BLOB, and see Understanding Row Versioning-Based Isolation Levels for a lecture on SNAPSHOT.
But using a BLOB may be overkill, you could get away with something much simpler. For instance, if you only have one ASP.Net process, then you could have a global volatile variable for the current file name. The writer writes the JPG into a new file, and then updates the global 'current' file name with an Interlocked.CompareExchange operation (it has to be Compare because a newer writer might actually finish faster, outrun a previous writer, and you want to preserve the latest update). There are still some issues left to solve (find out the file name at startup, clean up old files etc) but they are all fairly ease to solve.
If you have a farm of servers, or multiple ASP.Net processes serving the site, then things could get complicated. I would still do a rotating file name and do a try-and-error approach (try to respond with newest file, fall back to previous older one if conflict is detected).
You could get the bot to write the data to a different filename and then do a delete and rename to the filename being served by ASP.Net. This should reduce the file lock time down to the time for a delete and rename to occur. To clarify:
ASP.Net serving image from "webcam.jpg"
bot writes image data to "temp.jpg"
when last image byte written, bot deletes "webcam.jpg" and renames "temp.jpg" to "webcam.jpg"
ASP.Net should check "webcam.jpg" exists, if not wait 10ms (or suitable small increment) and check again.