How? upload multiple files with jsp and save then in a mysql database


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 9 of 9

Thread: How? upload multiple files with jsp and save then in a mysql database

  1. #1
    Join Date
    May 2006
    Posts
    8

    Question How? upload multiple files with jsp and save then in a mysql database

    I want to upload multiple files from a jsp and save these files into a mysql database.
    I'm relatively new to java. So what do I have to do?

    Can anyone help me?

  2. #2
    Join Date
    Feb 2006
    Location
    Cologne - Germany
    Posts
    271
    use the fileupload-api from apache.

  3. #3
    Join Date
    May 2006
    Posts
    8

    Question more questions

    Thanks for the answer,

    Please, can you post a sample? I don't know how to use the fileupload api.
    And what do I have to do to save uploaded files to a database?

    Thanks in advance

  4. #4
    Join Date
    Feb 2006
    Location
    Cologne - Germany
    Posts
    271
    If you just want to store the data in the database, have a look at my extensions to the fileupload api, which contain a utility class, that will provide you the formdata as a map:
    http://narcanti.keyboardsamurais.de/...leuploads.html

  5. #5
    Join Date
    May 2006
    Posts
    8

    Sorry, Stupid question

    Which code has to be in my servlet?

  6. #6
    Join Date
    Feb 2006
    Location
    Cologne - Germany
    Posts
    271
    Map parameters = ServletRequestUtil.readParameters(httpRequest);
    //reading a file
    byte [] filedata = (byte []) parameters.get("file");
    // read a normal parameter
    String param = (String) parameters.get("name");

  7. #7
    Join Date
    May 2006
    Posts
    8
    Isn't it possible to iterate through the map and save the filename and the file itself to the database?

  8. #8
    Join Date
    Feb 2006
    Location
    Cologne - Germany
    Posts
    271
    of course you can iterate through the map, by using mymap.keySet().iterator(). this will give you the keys of the map, which you can use to get the corresponding values.
    my example extensions don't support for filename lookup. the data is mapped to the name of the fileupload control. however, you can modify the Util class and put the data into the map by using the filenames. they are stored in the getName() method of the fileitems. but be aware: a user can upload multiple files with exact the same filename, what results in overwriting the data in the map.

  9. #9
    Join Date
    May 2006
    Posts
    8

    Question

    Thanks so far.

    I tried to store the files as blob in a mysql Database, but I don't know how the objects in the map become blobs.

    Please, can you help me

Similar Threads

  1. upload an image file and save on webserver.
    By sandhyaharsh in forum Java
    Replies: 0
    Last Post: 11-15-2005, 07:23 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center