| Author |
File Name Problem
|
Praveen Ramachandran
Greenhorn
Joined: Jul 18, 2006
Posts: 16
|
|
Hello, I am real confused with a small issue with the file uploading part.when i upload a file say ImportantDocument.doc it gets uploaded correctly ,but the file name is changed to all smaller case like importantdocument.doc.This happens with almost all files which are uploaded.Please advice me on this . I am hereby pasting my file handler method for your perusal.Please advice me in this regard The code is as follows: private BWiseFileHandle getFileHandleFrom(FileItem item, String anAttrName, String anAttrLabel, String aPrefix, ActionErrorMap aMap) { String errorMsg = null ; BWiseFileHandle fh = null ; IBWiseSession bwSession = getBWiseSession(); if (item != null && item.getContentType() != null && item.getName().length() > 0 && bwSession != null) { if ( (item.getSize() > 0)) { //String[] splitted = item.getName().CASE_INSENSITIVE_ORDER.toString().split("\\\\") ; String[] splitted = item.getName().split("\\\\"); String uploadName = (splitted.length > 1 ? splitted[splitted.length - 1] : item.getName()); IBWiseClass repClass = bwSession.getClassByName(CLASS_BW_REPOSITORY); IDataObject currentObject = getCurrentDataObject(); if (currentObject != null) { String className = currentObject.getArrayData().getName(); String[] args = new String[1]; args[0] = className; // Check extension int index = uploadName.lastIndexOf("."); if ( (index > 0) && ( (index + 1) < uploadName.length())) { String extension = uploadName.substring(index + 1).toUpperCase(); String supportedFileTypes = (String) repClass.performOperation( "getSupportedFileTypesForClass", args); if ( (supportedFileTypes != null) && (supportedFileTypes.indexOf(extension) < 0)) { errorMsg = getLocalized( "com.bwise.waf.tag.RequestHelper.incorrectExtension") + ": " + extension; } try //praveen for A0606-1972 { if (extension.equals("ZIP")) { ZipInputStream zipstream = new ZipInputStream(item.getInputStream()); if (zipstream.getNextEntry() == null) { throw new IOException(); } } } catch (IOException e) { errorMsg = getLocalized("com.bwise.waf.tag.RequestHelper.empty-upload"); } //end for A0606-1972 } // Check size Integer maxSize = (Integer) repClass.performOperation("getMaxUploadSizeForClass", args); if ( (maxSize != null) && (maxSize.longValue() < item.getSize()) && (errorMsg == null)) { errorMsg = "\""+ uploadName + "\": " + getLocalized( "com.bwise.waf.tag.RequestHelper.file_too_large") + ": " + printAsByteSize(maxSize.longValue()); } } // Handle is returned if (errorMsg == null) { String fileHandle = getBWiseSession().putFile(uploadName, item.get()); if (fileHandle == null) { // FVD: might need translation, however didn't occur so far errorMsg = "Error, RequestHelper>>putfile("+uploadName+") failed!" ; } if (errorMsg == null) { fh = new BWiseFileHandle(fileHandle, anAttrName, uploadName); if (fh == null) { // FVD: might need translation, however didn't occur so far errorMsg = "Error, RequestHelper>>new BWiseFileHandle(" + anAttrName +", " + uploadName+") failed!" ; } } } } else { // Empty files are NOT supported errorMsg = getLocalized( "com.bwise.waf.tag.RequestHelper.empty-upload"); } } else { // Nothing uploaded.... } if (errorMsg != null) { if (anAttrLabel != null) { errorMsg = anAttrLabel + ":" + errorMsg; } String key = aPrefix + anAttrName; // @TODO temporary code: suppress identical error messages. // RiskValidationSessionAction/AbstractRiskAssessmentSession has overlap // in the validations which trigger this call twice for the same field // resulting in double 'too_big' messages. Iterator iter = aMap.keyIterator(); boolean bAlreadyExists = false; while (iter.hasNext() && !bAlreadyExists) { String existingKey = (String) iter.next(); if (existingKey.startsWith(key) && aMap.getError(existingKey).equals(errorMsg)) { bAlreadyExists = true; } } if (!bAlreadyExists) { // Add error with unique key name, otherwise // multiple errors will overwrite eachother. // Ensure that one (and only one) is added // with the original Prefix+AttrName to have the correct // field highlighted. if (aMap.containsKey(key)) { aMap.addError(key + aMap.getAllErrors().length + 1, errorMsg); } else { aMap.addError(key, errorMsg); } } } return fh ; }
|
 |
Ben Souther
Sheriff
Joined: Dec 11, 2004
Posts: 13410
|
|
Javaranch tip: If you are going to post more than a line or two of your code, wrap that code in a set of UBB Code tags. Doing so will help to preserve your code's indenting, making it easier to read. If it is easier to read, more people will actaully read it and you will stand a better chance of getting help with your question. See UseCodeTags for more help with UBB code tags.
|
Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
|
 |
Lanny Gilbert
Ranch Hand
Joined: Jun 11, 2002
Posts: 103
|
|
|
I'm assuming you're running this on windows. Windows doesn't preserve case, so I don't know of a good way offhand to make this work. Try a Google search. that might turn up something useful.
|
 |
 |
|
|
subject: File Name Problem
|
|
|