Go Back   Webmaster Malaysia Forum » Website Design & Development » Website Programming

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 22-03-2004, 05:55 PM
lcf's Avatar
lcf lcf is offline
Pro-Blogger
 
Join Date: Feb 2003
Location: Kluang, Johor
Posts: 2,376
Rep Power: 118
lcf will become famous soon enough
Send a message via ICQ to lcf Send a message via MSN to lcf Send a message via Yahoo to lcf
Question JSP: Upload Images with Custom filename

Dear webmasters,

Need some help here.
Do you have any idea about upload file/image using JSP and store the uploaded file with custom filename that we defined?

Any clue/tips/website/code pls?
Thank you in advance.

*I have search on Internet and dun get much helpful pages... :/
__________________
LiewCF | Malaysia Bloggers Forum
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 26-03-2004, 01:16 PM
Inspired Webmaster
 
Join Date: Feb 2004
Location: Shah Alam
Posts: 175
Rep Power: 62
hftey is on a distinguished road
Send a message via ICQ to hftey Send a message via MSN to hftey Send a message via Yahoo to hftey Send a message via Skype™ to hftey
Like ASP, JSP also need a third party library to do this. Do take a look at this

http://www.jguru.com/faq/view.jsp?EID=160
__________________
Venzon Solution Services
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 09-08-2004, 04:03 AM
New kid on the block
 
Join Date: Aug 2004
Location: Ipoh, Perak, Malaysia.
Posts: 2
Rep Power: 0
stanleyshyeoh is on a distinguished road
Jakarta Commons FileUpload.

Hi lcf,

I strongly suggests the Jakarta Commons FileUpload.

http://jakarta.apache.org/commons/fileupload/

The input form has to be "multipart/form-data" as follows:
Code:
<form action="/products/addCategory.jsp?action=submit&processFlowToken=<c:out value="${requestScope.processFlowToken}" />" method="post" enctype="multipart/form-data" name="frm_Product">
myUploadForm.jsp


Put the .jar into your library. Below are some of the key codes you'll be using in your java class.

Code:
import org.apache.commons.fileupload.*;

   ...
   ...

   DiskFileUpload upload = new DiskFileUpload();

   if ( upload.isMultipartContent(req) )  {
      List items = upload.parseRequest(req);
                        
      Iterator iter = items.iterator();
      while (iter.hasNext()) {
         FileItem item = (FileItem) iter.next();

         if ( item.isFormField() ) {

            // process normal input form fields		
            System.out.println("Field: " + item.getFieldName() );
	    System.out.println("Value: " + item.getString() );

         } else  {

  	    // process uploaded fields.
            File fullFile = new File( item.getName() );

            // finding the physical directory the image is going to be stored at 
            String dirPath = getServletContext().getRealPath("/products/images/");

            // just my own little modification to the uploaded image filename.
            String fileName = trimImgFileName(fullFile.getName(), item.getFieldName(), nextId);

            // writing the image file
            item.write( new File( dirPath, fileName ) );
         }
      }
   }

   ...
   ...

    private String trimImgFileName(String fileName, String fieldName, String nextId) {
        StringBuffer sb = new StringBuffer(fileName);
        sb.replace(0, sb.lastIndexOf("."), nextId + "_" + fieldName);
        return sb.toString();
    }
UploadProcessing.java

I'm just extracting a few key areas I suggest you'd look at. I hope I'm not confusing u.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to create a form which allow people to upload their images? eyeball Website Design 8 02-08-2005 12:42 PM
Need a custom toolbar??? besttoolbars Other Webmaster-related Services and Promotion 0 27-08-2004 03:33 PM
Custom toolbar? Easy! besttoolbars Other Webmaster-related Services and Promotion 0 24-06-2004 03:59 PM
Create a custom IE toolbar! besttoolbars Other Webmaster-related Services and Promotion 0 27-05-2004 06:37 PM
Custom Web Hosting Package? lcf Other Webmaster-related Services and Promotion 5 15-07-2003 09:14 AM


All times are GMT +8. The time now is 03:20 AM. Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0 vBulletin skin by ForumMonkeys.com.


WebmasterMalaysia.com is Proudly Hosted by Exabytes Semi Dedicated Server.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61