locked
Uploading to file system rather than database RRS feed

  • Question

  • User-125674096 posted

    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

    Thursday, April 10, 2008 4:40 PM

Answers

  • User1631759614 posted

    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.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 15, 2008 3:53 AM

All replies

  • User1052258516 posted

    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.

    Thursday, April 10, 2008 8:41 PM
  • User-125674096 posted

    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!

    Saturday, April 12, 2008 8:45 AM
  • User1631759614 posted

    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.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 15, 2008 3:53 AM
  • User-125674096 posted

    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!

     

    Wednesday, April 16, 2008 5:39 PM
  • User1631759614 posted

    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!

    Wednesday, April 16, 2008 8:07 PM
  • User-125674096 posted

    thanks for your insight!

    Saturday, April 19, 2008 3:40 AM