Java Code Examples for org.apache.struts.upload.FormFile#getFileName()
The following examples show how to use
org.apache.struts.upload.FormFile#getFileName() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MyTools.java From Films with Apache License 2.0 | 8 votes |
public static String uploadUserPhoto(HttpServletRequest request,FormFile ff,String id){ String newPhotoName=""; try{ //���Ǹ�ÿ���û������Լ����ļ���. String filePath=request.getSession().getServletContext().getRealPath("/"); //filePath���ǵ�ǰ���webӦ���Ǿ��·�� F:\apache-tomcat-6.0.20\webapps\xiaoneinew //E:\Workspaces\MyEclipse 10\.metadata\.me_tcat\webapps\Films\ InputStream stream = ff.getInputStream();// ���ļ����� String oldPhotoName=ff.getFileName(); newPhotoName=id+oldPhotoName.substring(oldPhotoName.indexOf("."), oldPhotoName.length()); String newFullNewPath=filePath+File.separator+"upload"+File.separator+ "Gravator"+File.separator + id +File.separator; //�ж�newFullNewPath�ļ����Ƿ���� File f=new File(newFullNewPath); if(!f.isDirectory()){ //�����ļ���,�������� f.mkdirs(); } //���ϴ���ͷ�������ɳ� ���.�� OutputStream bos = new FileOutputStream(newFullNewPath+ newPhotoName); int len = 0; byte[] buffer = new byte[8192]; while ((len = stream.read(buffer, 0, 8192)) != -1) { bos.write(buffer, 0, len);// ���ļ�д������� } bos.close(); stream.close(); } catch (Exception e) { e.printStackTrace(); } return newPhotoName; }
Example 2
Source File: AjaxAttachFileAction.java From ezScrum with GNU General Public License v2.0 | 6 votes |
private File convertToFile(FormFile formFile) throws IOException { String tempUploadFolder = "upload_tmp"; File folder = new File(tempUploadFolder); folder.mkdirs(); File file = new File(tempUploadFolder + File.separator + formFile.getFileName()); OutputStream os = new FileOutputStream(file); InputStream is = new BufferedInputStream(formFile.getInputStream()); int count; byte[] buffer = new byte[4096]; while ((count = is.read(buffer)) > -1) { os.write(buffer, 0, count); } os.close(); is.close(); return file; }
Example 3
Source File: ComMailingComponentsAction.java From openemm with GNU Affero General Public License v3.0 | 5 votes |
private boolean isValidPictureFiles(ComMailingComponentsForm form) { for (FormFile file : form.getAllFiles().values()) { String name = file.getFileName(); if (StringUtils.isEmpty(name)) { return false; } String extension = AgnUtils.getFileExtension(name); if (!ImageUtils.isValidImageFileExtension(extension) && !"zip".equalsIgnoreCase(extension)) { return false; } } return true; }
Example 4
Source File: FormComponentsAction.java From openemm with GNU Affero General Public License v3.0 | 5 votes |
private List<String> getInvalidFilenames(FormComponentsForm actionForm) { ArrayList<String> invalidFilenames = new ArrayList<>(); for (FormFile formFile : actionForm.getAllNewFiles().values()) { String filename = formFile.getFileName(); // Skip empty entries if (StringUtils.isNotBlank(filename)) { if (filename.chars().anyMatch(this::isInvalidFilenameCharacter)) { invalidFilenames.add(filename); } } } return invalidFilenames; }
Example 5
Source File: StrutsDelegate.java From uyuni with GNU General Public License v2.0 | 5 votes |
/** * Util to get the String file name of a file upload form. * * @param form to get the contents from * @param paramName of the FormFile * @return String file name of the upload. */ public String getFormFileName(DynaActionForm form, String paramName) { if (form.getDynaClass().getDynaProperty(paramName) == null) { return ""; } FormFile f = (FormFile)form.get(paramName); return f.getFileName(); }
Example 6
Source File: ConfigFileForm.java From uyuni with GNU General Public License v2.0 | 5 votes |
/** * Validate a file-upload. This checks that: * <ul> * <li>The file exists * <li>The file isn't too large * <li>If the file is text, its contents are valid after macro-substitution * </ul> * @param request the incoming request * @return a ValidatorResult.. The list is empty if everything is OK */ public ValidatorResult validateUpload(HttpServletRequest request) { ValidatorResult msgs = new ValidatorResult(); FormFile file = (FormFile)get(REV_UPLOAD); //make sure there is a file if (file == null || file.getFileName() == null || file.getFileName().trim().length() == 0) { msgs.addError(new ValidatorError("error.config-not-specified")); } else if (file.getFileSize() == 0) { msgs.addError(new ValidatorError("error.config-empty", file.getFileName())); } //make sure they didn't send in something huge else if (file.getFileSize() > ConfigFile.getMaxFileSize()) { msgs.addError(new ValidatorError("error.configtoolarge", StringUtil.displayFileSize(ConfigFile.getMaxFileSize(), false))); } // It exists and isn't too big - is it text? else if (!isBinary()) { try { String content = new String(file.getFileData()); String startDelim = getString(REV_MACROSTART); String endDelim = getString(REV_MACROEND); msgs.append(ConfigurationValidation.validateContent( content, startDelim, endDelim)); } catch (Exception e) { msgs.addError(new ValidatorError("error.fatalupload", StringUtil.displayFileSize( ConfigFile.getMaxFileSize(), false))); } } return msgs; }
Example 7
Source File: ItemParserBase.java From kfs with GNU Affero General Public License v3.0 | 5 votes |
/** * Checks whether the specified item import file is not null and of a valid format; * throws exceptions if conditions not satisfied. * * @param itemClass the specified item import file */ protected void checkItemFile(FormFile itemFile) { if (itemFile == null) { throw new ItemParserException("invalid (null) item import file", KFSKeyConstants.ERROR_UPLOADFILE_NULL); } String fileName = itemFile.getFileName(); if (StringUtils.isNotBlank(fileName) && !StringUtils.lowerCase(fileName).endsWith(".csv") && !StringUtils.lowerCase(fileName).endsWith(".xls")) { throw new ItemParserException("unsupported item import file format: " + fileName, ERROR_ITEMPARSER_INVALID_FILE_FORMAT, fileName); } }
Example 8
Source File: StrutsDelegate.java From spacewalk with GNU General Public License v2.0 | 5 votes |
/** * Util to get the String file name of a file upload form. * * @param form to get the contents from * @param paramName of the FormFile * @return String file name of the upload. */ public String getFormFileName(DynaActionForm form, String paramName) { if (form.getDynaClass().getDynaProperty(paramName) == null) { return ""; } FormFile f = (FormFile)form.get(paramName); return f.getFileName(); }
Example 9
Source File: ConfigFileForm.java From spacewalk with GNU General Public License v2.0 | 5 votes |
/** * Validate a file-upload. This checks that: * <ul> * <li>The file exists * <li>The file isn't too large * <li>If the file is text, its contents are valid after macro-substitution * </ul> * @param request the incoming request * @return a ValidatorResult.. The list is empty if everything is OK */ public ValidatorResult validateUpload(HttpServletRequest request) { ValidatorResult msgs = new ValidatorResult(); FormFile file = (FormFile)get(REV_UPLOAD); //make sure there is a file if (file == null || file.getFileName() == null || file.getFileName().trim().length() == 0) { msgs.addError(new ValidatorError("error.config-not-specified")); } else if (file.getFileSize() == 0) { msgs.addError(new ValidatorError("error.config-empty", file.getFileName())); } //make sure they didn't send in something huge else if (file.getFileSize() > ConfigFile.getMaxFileSize()) { msgs.addError(new ValidatorError("error.configtoolarge", StringUtil.displayFileSize(ConfigFile.getMaxFileSize(), false))); } // It exists and isn't too big - is it text? else if (!isBinary()) { try { String content = new String(file.getFileData()); String startDelim = getString(REV_MACROSTART); String endDelim = getString(REV_MACROEND); msgs.append(ConfigurationValidation.validateContent( content, startDelim, endDelim)); } catch (Exception e) { msgs.addError(new ValidatorError("error.fatalupload", StringUtil.displayFileSize( ConfigFile.getMaxFileSize(), false))); } } return msgs; }
Example 10
Source File: MyTools.java From Films with Apache License 2.0 | 5 votes |
public static String uploadFilmPhoto(HttpServletRequest request,FormFile ff,String id){ String newPhotoName=""; try{ //���Ǹ�ÿ���û������Լ����ļ���. String filePath=request.getSession().getServletContext().getRealPath("/"); //filePath���ǵ�ǰ���webӦ���Ǿ��·�� F:\apache-tomcat-6.0.20\webapps\xiaoneinew //E:\Workspaces\MyEclipse 10\.metadata\.me_tcat\webapps\Films\ InputStream stream = ff.getInputStream();// ���ļ����� String oldPhotoName=ff.getFileName(); newPhotoName=id+oldPhotoName.substring(oldPhotoName.indexOf("."), oldPhotoName.length()); String newFullNewPath=filePath+File.separator+"upload"+File.separator+"movie"+File.separator; //�ж�newFullNewPath�ļ����Ƿ���� File f=new File(newFullNewPath); if(!f.isDirectory()){ //�����ļ���,�������� f.mkdirs(); } //���ϴ���ͷ�������ɳ� ���.�� OutputStream bos = new FileOutputStream(newFullNewPath+ newPhotoName); int len = 0; byte[] buffer = new byte[8192]; while ((len = stream.read(buffer, 0, 8192)) != -1) { bos.write(buffer, 0, len);// ���ļ�д������� } bos.close(); stream.close(); } catch (Exception e) { e.printStackTrace(); } return newPhotoName; }
Example 11
Source File: ComMailingComponentsAction.java From openemm with GNU Affero General Public License v3.0 | 4 votes |
protected void addUploadedFiles(ComMailingComponentsForm componentForm, Mailing mailing, HttpServletRequest req, ActionMessages messages, ActionMessages errors) throws Exception { Set<Integer> indices = componentForm.getIndices(); int foundItemsToStore = 0; int successfullyStoredItems = 0; for (int index : indices) { // Check if any part of this item was filled at all FormFile file = componentForm.getNewFile(index); if (file != null && StringUtils.isNotBlank(file.getFileName()) && file.getFileName().toLowerCase().endsWith(".zip")) { ComMailingComponentsService.UploadStatistics statistics = mailingComponentService.uploadZipArchive(mailing, file); foundItemsToStore += statistics.getFound(); successfullyStoredItems += statistics.getStored(); writeUserActivityLog(AgnUtils.getAdmin(req), "upload mailing component file", "Mailing ID: " + mailing.getId() + ", type: ZIP, Name: " + file.getFileName() + ", found items to store: " + statistics.getFound() + ", successfully stored items: " + statistics.getStored()); } else { String link = componentForm.getLink(index); String description = componentForm.getDescriptionByIndex(index); String baseComponentForMobileComponent = componentForm.getMobileComponentBaseComponent(index); if ((file != null && StringUtils.isNotBlank(file.getFileName())) || StringUtils.isNotBlank(link) || StringUtils.isNotBlank(description) || StringUtils.isNotBlank(baseComponentForMobileComponent)) { foundItemsToStore++; // Check if mandatory parts are missing if (file == null || StringUtils.isBlank(file.getFileName())) { errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("mailing.errors.no_component_file")); } else { String newComponentName = null; if (StringUtils.isNotBlank(baseComponentForMobileComponent)) { newComponentName = ShowImageServlet.MOBILE_IMAGE_PREFIX + baseComponentForMobileComponent; if (StringUtils.isBlank(description)) { description = "Mobile component for " + baseComponentForMobileComponent; } else { description = description + " / Mobile component for " + baseComponentForMobileComponent; } } if (StringUtils.isBlank(newComponentName)) { newComponentName = file.getFileName(); } try { if (file.getFileSize() > 0) { MailingComponent component = mailing.getComponents().get(newComponentName); if (component != null && component.getType() == MailingComponent.TYPE_HOSTED_IMAGE) { // Update existing image component.setBinaryBlock(file.getFileData(), file.getContentType()); component.setLink(link); component.setDescription(description); } else { // Store new image component = new MailingComponentImpl(); component.setCompanyID(mailing.getCompanyID()); component.setMailingID(componentForm.getMailingID()); component.setType(MailingComponent.TYPE_HOSTED_IMAGE); component.setDescription(description); component.setComponentName(newComponentName); component.setBinaryBlock(file.getFileData(), file.getContentType()); component.setLink(link); mailing.addComponent(component); } } } catch (Exception e) { logger.error("saveComponent: " + e); } if (componentForm.getAction() == ACTION_SAVE_COMPONENT_EDIT) { req.setAttribute("file_path", AgnUtils.getAdmin(req).getCompany().getRdirDomain() + "/image?ci=" + mailing.getCompanyID() + "&mi=" + componentForm.getMailingID() + "&name=" + file.getFileName()); } // Reset MobileComponentBaseComponent for next upload request from gui componentForm.setMobileComponentBaseComponent(index, ""); successfullyStoredItems++; writeUserActivityLog(AgnUtils.getAdmin(req), "upload mailing component file", "Mailing ID: "+mailing.getId() + ", type: image, name: " + newComponentName); } } } } if (foundItemsToStore > 0) { messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("items_saved", successfullyStoredItems, foundItemsToStore)); } }
Example 12
Source File: InquiryAction.java From unitime with Apache License 2.0 | 4 votes |
public Attachment(FormFile file) throws IOException { iName = file.getFileName(); iData = file.getFileData(); iContentType = file.getContentType(); }