Hi all,
For performance reasons i wish to upload the photos to a folder rather than database. Can someone explain to me which parts of the code i need to change. I assume some of the functions in photomanager.vb.
I understand i will need to save locations in the table, i.e thumbnail, midsize and large.
Actually you don't have to store the locations in the DB at all. The easiest thing to do is to use the database ID's as folder and file names. Take the directory structure:
As you can see the ID's from the database make up the dynamic part of the folder structure while the rest are static and can be hardcoded in the code. You assume that all of the static will be controled by you so it's not a big deal. When you add an new
album then create the album folder, each time you save a photo the code creates the three versions of the image and save them to the filesystem with the id of the photo info you saved to the db.
If you need a code example you can download my version of the PWSK and look at the PhotoManager code in the Provider folder. This is how I did it.
You've made some great mods - your using a .dll to upload though, i can't use dlls so not much use unfourtuantly.
anyone else able to help? if someone could point out which parts of the code i need to modify then that would be a great help!.
My aim is to be able to upload 5 photos at a time, the copy all to upload folder won't be required, i want to manage the whole site from the web rather than ftping.
Alright, this is doable, but I hope you have some c# or vb experience.
1. Delete the image columns of your database and add a column to store a filename instead of an image. I'll leave type and size up to you.
2. In PhotoManager::GetPhoto(int, PhotoSize) you are going to need to extract the filename string from the DB, retrieve the file, resize it, store it as a temp, then return a MemoryStream to it. Your other option would be to store 4 copies like its done
in the database. You would then need to store 4 filenames in the DB or append a number, letter, etc to the end of the filenames to indicate the size.
3. In PhotoManager::AddPhoto(int, string, byte[]) you are going to need to store the filename(s) in the DB, then write the file(s) to the folder. Some sort of predefined naming convention is a must.
4. You will need to edit two of the stored procedures in the database to accomodate what you have done above. They are AddPhoto and GetPhoto and are respectively called by the functions you are modifying above.
The main concept that you need to follow is that any function you modify in the PhotoManager class must maintain is functionality, parameters, and return type. Other than that, code away. This is definately not a task to be taken on by a beginner. If you
are new to this stuff, I would highly recommend making a copy of your website to give this a shot in.
FYI: Drag and Drop features are not available to Forms in VS2005 or VS2008, when debugging, if you started VS with admin privleges.
thanks for your advice. I have successfully completed now. Performance seems to have got worse though, i am resizing on each call rather than on the initial upload - probably the issue!
Great answer though, gave me a bit of structure to focus on!
The performance is all gonna be based on the server your site is hosted on. That is all server side code. Personally, I would store the 4 copies, you may see an incredible performance increase. Your other option would be to make another table to store the
full size images in the database. The smaller pics will not create any performance problems and the large pic is only accessed by the download page. I personally got rid of the download page and wrote a function that sends the full size pic to the web browser
when you click download. Its all just stuff to play around with. Good Luck!
FYI: Drag and Drop features are not available to Forms in VS2005 or VS2008, when debugging, if you started VS with admin privleges.
Member
23 Points
30 Posts
Uploading to file system rather than database
Apr 10, 2008 04:40 PM|igotnushooz|LINK
Hi all,
For performance reasons i wish to upload the photos to a folder rather than database. Can someone explain to me which parts of the code i need to change. I assume some of the functions in photomanager.vb.
I understand i will need to save locations in the table, i.e thumbnail, midsize and large.
Any help will be most apreciated!
cheers
Star
7692 Points
1845 Posts
Re: Uploading to file system rather than database
Apr 10, 2008 08:41 PM|whighfield|LINK
Actually you don't have to store the locations in the DB at all. The easiest thing to do is to use the database ID's as folder and file names. Take the directory structure:
<WEB_ROOT>\Albums\Album_<ALBUMID>\PHOTOID_low.jpg
<WEB_ROOT>\Albums\Album_<ALBUMID>\PHOTOID_high.jpg
<WEB_ROOT>\Albums\Album_<ALBUMID>\PHOTOID_thumb.jpg
<WEB_ROOT>\Albums\Album_<ALBUMID>\PHOTOID_original.jpg
As you can see the ID's from the database make up the dynamic part of the folder structure while the rest are static and can be hardcoded in the code. You assume that all of the static will be controled by you so it's not a big deal. When you add an new album then create the album folder, each time you save a photo the code creates the three versions of the image and save them to the filesystem with the id of the photo info you saved to the db.
If you need a code example you can download my version of the PWSK and look at the PhotoManager code in the Provider folder. This is how I did it.
Member
23 Points
30 Posts
Re: Uploading to file system rather than database
Apr 12, 2008 08:45 AM|igotnushooz|LINK
You've made some great mods - your using a .dll to upload though, i can't use dlls so not much use unfourtuantly.
anyone else able to help? if someone could point out which parts of the code i need to modify then that would be a great help!.
My aim is to be able to upload 5 photos at a time, the copy all to upload folder won't be required, i want to manage the whole site from the web rather than ftping.
thanks!
Member
62 Points
37 Posts
Re: Uploading to file system rather than database
Apr 15, 2008 03:53 AM|crf250guy|LINK
Alright, this is doable, but I hope you have some c# or vb experience.
1. Delete the image columns of your database and add a column to store a filename instead of an image. I'll leave type and size up to you.
2. In PhotoManager::GetPhoto(int, PhotoSize) you are going to need to extract the filename string from the DB, retrieve the file, resize it, store it as a temp, then return a MemoryStream to it. Your other option would be to store 4 copies like its done in the database. You would then need to store 4 filenames in the DB or append a number, letter, etc to the end of the filenames to indicate the size.
3. In PhotoManager::AddPhoto(int, string, byte[]) you are going to need to store the filename(s) in the DB, then write the file(s) to the folder. Some sort of predefined naming convention is a must.
4. You will need to edit two of the stored procedures in the database to accomodate what you have done above. They are AddPhoto and GetPhoto and are respectively called by the functions you are modifying above.
The main concept that you need to follow is that any function you modify in the PhotoManager class must maintain is functionality, parameters, and return type. Other than that, code away. This is definately not a task to be taken on by a beginner. If you are new to this stuff, I would highly recommend making a copy of your website to give this a shot in.
Member
23 Points
30 Posts
Re: Uploading to file system rather than database
Apr 16, 2008 05:39 PM|igotnushooz|LINK
thanks for your advice. I have successfully completed now. Performance seems to have got worse though, i am resizing on each call rather than on the initial upload - probably the issue!
Great answer though, gave me a bit of structure to focus on!
Member
62 Points
37 Posts
Re: Uploading to file system rather than database
Apr 16, 2008 08:07 PM|crf250guy|LINK
The performance is all gonna be based on the server your site is hosted on. That is all server side code. Personally, I would store the 4 copies, you may see an incredible performance increase. Your other option would be to make another table to store the full size images in the database. The smaller pics will not create any performance problems and the large pic is only accessed by the download page. I personally got rid of the download page and wrote a function that sends the full size pic to the web browser when you click download. Its all just stuff to play around with. Good Luck!
Member
23 Points
30 Posts
Re: Uploading to file system rather than database
Apr 19, 2008 03:40 AM|igotnushooz|LINK
thanks for your insight!