List of usage examples for org.springframework.web.multipart MultipartFile getOriginalFilename
@Nullable String getOriginalFilename();
From source file:ru.langboost.controllers.file.FileHelper.java
private static String generateFileName(MultipartFile multipartFile) { if (multipartFile.getOriginalFilename() == null || "".equals(multipartFile.getOriginalFilename())) { return File.DEFAULT_FILENAME + "." + File.DEFAULT_IMAGE_FORMAT; } else {/*from ww w .j av a2 s .co m*/ return multipartFile.getOriginalFilename(); } }
From source file:com.bookselling.util.FileUtilities.java
public static File multipartToFile(MultipartFile multipart) { try {//www . j a v a2 s .c om File convFile = new File(multipart.getOriginalFilename()); multipart.transferTo(convFile); return convFile; } catch (Exception ex) { return null; } }
From source file:il.co.brandis.utils.FileUploaderUtil.java
public static void saveFile(MultipartFile file, String saveDir) throws IllegalStateException, IOException { String fileName = file.getOriginalFilename(); System.out.println("Saving file: " + file.getOriginalFilename()); if (!fileName.equals("")) { file.transferTo(new File(saveDir + fileName)); }// ww w . ja va 2 s. co m }
From source file:de.unimannheim.spa.process.util.FileUtils.java
public static File convertMultipartToFile(MultipartFile multipartFile) throws IllegalStateException, IOException { File convertedFile = new File(multipartFile.getOriginalFilename()); FileOutputStream fos = new FileOutputStream(convertedFile); fos.write(multipartFile.getBytes()); fos.close();/*from ww w.ja va2s . com*/ return convertedFile; }
From source file:com.beginner.core.utils.FileUpload.java
/** * /* www.j av a 2s . com*/ * @param file * @param filePath * @param fileName ?? * @return String ?? */ public static String fileUp(MultipartFile file, String filePath, String fileName) { String extName = ""; try { if (file.getOriginalFilename().lastIndexOf(".") >= 0) { extName = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")); } copyFile(file.getInputStream(), filePath, fileName + extName).replaceAll("-", ""); } catch (IOException e) { System.out.println(e); } return fileName + extName; }
From source file:ee.sk.hwcrypto.demo.model.FileWrapper.java
public static FileWrapper create(MultipartFile multipartFile) throws IOException { FileWrapper file = new FileWrapper(); file.setBytes(multipartFile.getBytes()); file.setFileName(multipartFile.getOriginalFilename()); file.setMimeType(multipartFile.getContentType()); return file;//www .j av a 2 s. c o m }
From source file:org.shareok.data.dspacemanager.DspaceJournalDataUtil.java
/** * //from ww w . j ava 2 s . co m * @param file : the uploaded file * @param publisher : journal publisher, e.g. sage or plos * @return : the path of the uploading folder */ public static String saveUploadedData(MultipartFile file, String publisher) { String uploadedFilePath = null; try { String oldFileName = file.getOriginalFilename(); String extension = DocumentProcessorUtil.getFileExtension(oldFileName); oldFileName = DocumentProcessorUtil.getFileNameWithoutExtension(oldFileName); //In the future the new file name will also has the user name String time = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss").format(new Date()); String newFileName = oldFileName + "--" + time + "." + extension; String uploadPath = getDspaceJournalUploadFolderPath(publisher); if (null != uploadPath) { File uploadFolder = new File(uploadPath); if (!uploadFolder.exists()) { uploadFolder.mkdir(); } File uploadTimeFolder = new File(uploadPath + File.separator + time); if (!uploadTimeFolder.exists()) { uploadTimeFolder.mkdir(); } } uploadedFilePath = uploadPath + File.separator + time + File.separator + newFileName; File uploadedFile = new File(uploadedFilePath); file.transferTo(uploadedFile); } catch (Exception ex) { Logger.getLogger(DspaceJournalDataUtil.class.getName()).log(Level.SEVERE, null, ex); } return uploadedFilePath; }
From source file:hr.softwarecity.osijek.utility.Multimedia.java
/** * Method for uploading files// w ww.j a v a 2 s . c o m * @param path path to put file * @param file file to upload * @return path to file or Failed keyword on fail * @throws java.nio.file.FileSystemException * @throws java.io.FileNotFoundException */ public static String handleFileUpload(String path, MultipartFile file) throws IOException { Logger.getLogger("Multimedia.java").log(Logger.Level.INFO, "Initiating file upload"); if (!file.isEmpty()) { byte[] bytes = file.getBytes(); BufferedOutputStream stream = new BufferedOutputStream( new FileOutputStream(new File(path, file.getOriginalFilename()))); stream.write(bytes); stream.close(); Logger.getLogger("Multimedia.java").log(Logger.Level.INFO, "File uploaded"); return path; } else { Logger.getLogger("Multimedia.java").log(Logger.Level.ERROR, "File size 0! "); return null; } }
From source file:com.glaf.core.util.UploadUtils.java
/** * ????/* w w w .j a va2 s.c o m*/ * * @param request * @param fileParam * @param fileType * ?:jpg,gif,png,jpeg,swf * @param fileSize * MB?? * @return status=0 ?<br/> * status=1 <br/> * status=2 ?<br/> */ public static int getUploadStatus(HttpServletRequest request, String fileParam, String fileType, long fileSize) { int status = 0; MultipartFile mFile = getMultipartFile(request, fileParam); if (!mFile.isEmpty()) { String ext = FileUtils.getFileExt(mFile.getOriginalFilename()); if (!StringUtils.containsIgnoreCase(fileType, ext)) { status = 1; } long size = mFile.getSize(); if (fileSize != -1 && size > FileUtils.MB_SIZE * fileSize) { status = 2; } } return status; }
From source file:cn.guoyukun.spring.web.upload.FileUploadUtils.java
public static final String extractFilename(MultipartFile file, String baseDir, boolean needDatePathAndRandomName) throws UnsupportedEncodingException { String filename = file.getOriginalFilename(); int slashIndex = filename.indexOf("/"); if (slashIndex >= 0) { filename = filename.substring(slashIndex + 1); }//from w w w . j av a 2 s. c o m if (needDatePathAndRandomName) { filename = baseDir + File.separator + datePath() + File.separator + encodingFilename(filename); } else { filename = baseDir + File.separator + filename; } return filename; }