Return-Path: Delivered-To: apmail-commons-user-archive@www.apache.org Received: (qmail 81862 invoked from network); 6 Jul 2009 13:44:37 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 6 Jul 2009 13:44:37 -0000 Received: (qmail 15202 invoked by uid 500); 6 Jul 2009 13:44:45 -0000 Delivered-To: apmail-commons-user-archive@commons.apache.org Received: (qmail 15108 invoked by uid 500); 6 Jul 2009 13:44:45 -0000 Mailing-List: contact user-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Users List" Delivered-To: mailing list user@commons.apache.org Received: (qmail 15098 invoked by uid 99); 6 Jul 2009 13:44:44 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 06 Jul 2009 13:44:44 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of lists@nabble.com designates 216.139.236.158 as permitted sender) Received: from [216.139.236.158] (HELO kuber.nabble.com) (216.139.236.158) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 06 Jul 2009 13:44:33 +0000 Received: from isper.nabble.com ([192.168.236.156]) by kuber.nabble.com with esmtp (Exim 4.63) (envelope-from ) id 1MNoUO-0004iL-HX for user@commons.apache.org; Mon, 06 Jul 2009 06:44:12 -0700 Message-ID: <24355676.post@talk.nabble.com> Date: Mon, 6 Jul 2009 06:44:12 -0700 (PDT) From: Mathias Nilsson To: user@commons.apache.org Subject: + % in file name MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Nabble-From: wicket.programmer@gmail.com X-Virus-Checked: Checked by ClamAV on apache.org Hi, When trying to upload a file with ( %+ ) characters in file name they are stripped. Here is my code @Override protected void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException { FileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload upload = new ServletFileUpload(factory); upload.setHeaderEncoding("ISO-8859-1"); FileUploadListener listener = null; if( Session.exists() ){ if( Session.get() instanceof IUploadable ){ listener = new FileUploadListener(); ((IUploadable) Session.get()).setFileUploadListener( listener ); ((IUploadable) Session.get()).setUploadTransfer( null ); } } if( listener == null ){ ErrorTransfer transfer = new ErrorTransfer(); transfer.setDescription( "No listener found" ); ((IUploadable) Session.get()).setUploadTransfer(transfer); ((IUploadable) Session.get()).setFileUploadListener( null ); return; } upload.setProgressListener(listener); try { // iterate over all uploaded files List uploadedItems = upload.parseRequest(request); Iterator i = uploadedItems.iterator(); String description = ""; while (i.hasNext()) { FileItem fileItem = (FileItem) i.next(); if (fileItem.isFormField() == false) { if (fileItem.getSize() > 0) { File uploadedFile = null; String myFullFileName = new String (fileItem.getName().getBytes( "ISO-8859-1" )), filteredName = "", myFileName = "", slashType = (myFullFileName.lastIndexOf("\\") > 0) ? "\\" : "/";// Windows or UNIX int startIndex = myFullFileName.lastIndexOf(slashType); // Ignore the path and get the filename myFileName = myFullFileName.substring(startIndex + 1, myFullFileName.length()); filteredName = new String( myFileName ); File path = null; if( Application.get( applicationName) instanceof IUploadableApplication ){ path = ((IUploadableApplication) Application.get( applicationName)).getUploadPath(); List filters = ((IUploadableApplication) Application.get( applicationName)).getUploadNameFilters(); if( filters != null ){ for( INameFilter filter : filters ){ filteredName = filter.getTransformName( filteredName ); } } } // Create new File object uploadedFile = new File( path , filteredName); // Write the uploaded file to the system fileItem.write(uploadedFile); FileTransfer transfer = new FileTransfer(); transfer.setFilteredName( new File( path , filteredName ).getAbsolutePath() ); transfer.setOriginalName( new File( path , myFileName ).getAbsolutePath() ); ((IUploadable) Session.get()).setUploadTransfer(transfer); } } } } catch (FileUploadException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } } -- View this message in context: http://www.nabble.com/%2B---in-file-name-tp24355676p24355676.html Sent from the Commons - User mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@commons.apache.org For additional commands, e-mail: user-help@commons.apache.org