Example usage for org.springframework.web.multipart MultipartFile getOriginalFilename

List of usage examples for org.springframework.web.multipart MultipartFile getOriginalFilename

Introduction

In this page you can find the example usage for org.springframework.web.multipart MultipartFile getOriginalFilename.

Prototype

@Nullable
String getOriginalFilename();

Source Link

Document

Return the original filename in the client's filesystem.

Usage

From source file:com.opendesign.utils.CmnUtil.java

/**
 * ? ? /*from  w  w  w.  j a v  a 2  s.c om*/
 * 
 * @param request
 * @param fileParamName
 * @param subDomain
 * @return
 * @throws IOException
 */
public static String handleFileUploadGetOriFileName(MultipartHttpServletRequest request, String fileParamName)
        throws IOException {
    MultipartFile reqFile = request.getFile(fileParamName);
    String oriFileName = "";
    if (reqFile != null) {
        oriFileName = reqFile.getOriginalFilename();
    }
    return oriFileName;
}

From source file:com.opendesign.utils.CmnUtil.java

/**
 * ? //from  w ww  .  java 2s. com
 * 
 * @param multipartFile
 * @param fileUploadDir
 * @param saveFileName
 * @return
 * @throws IllegalStateException
 * @throws IOException
 */
public static File saveFile(MultipartFile multipartFile, String fileUploadDir, String saveFileName)
        throws IllegalStateException, IOException {
    String originalFilename = multipartFile.getOriginalFilename();
    String ext = FilenameUtils.getExtension(originalFilename);
    saveFileName = saveFileName + "." + ext;

    // System.out.println(saveFileName);
    // System.out.println(fileUploadDir);

    File directory = new File(fileUploadDir);
    if (!directory.exists()) {
        directory.mkdirs();
    }

    File file = new File(directory, saveFileName);
    multipartFile.transferTo(file);

    return file;
}

From source file:com.ylife.goods.model.UploadUtil.java

/**
 * ??/*from ww  w .  ja  v  a2s.co m*/
 * 
 * @param muFile
 *            MultipartFile
 * @param request
 *            HttpServletRequest
 * @return ???Map
 * @throws java.io.IOException
 *             
 */
public static synchronized Map<String, String> testUpYun(MultipartFile muFile, HttpServletRequest request)
        throws IOException {
    Map<String, String> map = new HashMap<String, String>();
    UpyunConf upConf = sysHelperMapper.selectUpyunConf();
    if (muFile != null && muFile.getSize() != 0) {
        // ???
        if (!checkFileForSpringUpload(muFile)) {
            throw new RuntimeException("" + muFile.getOriginalFilename() + LOGGERINFO1);
        }
        // ???
        if (upConf != null) {
            // ???
            map = uploadImgUpyun.testUpYun(muFile, upConf);
        }
        return map;
    } else {
        return null;
    }
}

From source file:com.eryansky.modules.disk.utils.DiskUtils.java

/**
 * ?/* ww w .j  av a  2s.com*/
 *
 * @param folderCode
 *            ?
 * @param sessionInfo
 *            session? ??null
 * @param multipartFile
 *             SpringMVC
 * @return
 * @throws InvalidExtensionException
 * @throws FileUploadBase.FileSizeLimitExceededException
 * @throws FileNameLengthLimitExceededException
 * @throws IOException
 */
public static File saveSystemFile(String folderCode, SessionInfo sessionInfo, MultipartFile multipartFile)
        throws InvalidExtensionException, FileUploadBase.FileSizeLimitExceededException,
        FileNameLengthLimitExceededException, IOException {
    String userId = null;
    if (sessionInfo != null && sessionInfo.getUserId() != null) {
        userId = sessionInfo.getUserId();
    }

    String code = FileUploadUtils.encodingFilenamePrefix(userId + "", multipartFile.getOriginalFilename());
    Folder folder = getSystemFolderByCode(folderCode, userId);
    String storeFilePath = iFileManager.getStorePath(folder, userId, multipartFile.getOriginalFilename());
    File file = new File();
    file.setFolder(folder);
    file.setCode(code);
    file.setUserId(userId);
    file.setName(multipartFile.getOriginalFilename());
    file.setFilePath(storeFilePath);
    file.setFileSize(multipartFile.getSize());
    file.setFileSuffix(FilenameUtils.getExtension(multipartFile.getOriginalFilename()));
    iFileManager.saveFile(file.getFilePath(), multipartFile.getInputStream(), true);
    diskManager.saveFile(file);
    return file;
}

From source file:com.ylife.goods.model.UploadUtil.java

/**
 * ?//from www  . j  a v a  2s .  co m
 * 
 * @param muFile
 *            
 * @param request
 *            HttpServletRequest
 * @return String
 */
public static synchronized String uploadFileOne(MultipartFile muFile, HttpServletRequest request) {
    Map<String, String> map = new HashMap<String, String>();
    UpyunConf upConf = sysHelperMapper.selectUpyunConf();
    FastDFSInfo fastdfs = fastDFSService.getFastDFSInfoByCurr();
    if (muFile != null && muFile.getSize() != 0) {
        // ???
        if (!checkFileForSpringUpload(muFile)) {
            throw new RuntimeException("" + muFile.getOriginalFilename() + LOGGERINFO1);
        }
        // ???
        if (upConf != null && "1".equals(upConf.getUsedStatus())) {
            // ???
            if (null == fastdfs || "0".equals(fastdfs.getUserd())) {
                map = uploadImgUpyun.uploadForOldAndSmall(muFile, upConf);
            } else {
                // FastDFS
                map = uploadImgUpyun.uploadForOldAndSmall(muFile, upConf);
                map = uploadImgFastDFS.saveToFastDFS(map, fastdfs);
            }
        } else {
            // Java?
            // ??
            if (null == fastdfs || "0".equals(fastdfs.getUserd())) {
                map = uploadImgJava.uploadForOldAndSmall(muFile);
            } else {
                // FastDFS
                map = uploadImgJava.uploadForOldAndSmallSaveFastDFS(muFile);
                map = uploadImgFastDFS.saveToFastDFS(map, fastdfs);
            }
        }
        return map.get("oldimg");
    } else {
        return null;
    }
}

From source file:com.ylife.goods.model.UploadUtil.java

/**
 * ?/*from  w  w w . j  a v a  2  s.com*/
 * 
 * @param muFile
 *            
 * @param request
 *            HttpServletRequest
 * @return String
 */
public static synchronized String uploadFileCustomerHeadOne(MultipartFile muFile, HttpServletRequest request) {
    Map<String, String> map = new HashMap<String, String>();
    UpyunConf upConf = sysHelperMapper.selectUpyunConf();
    FastDFSInfo fastdfs = fastDFSService.getFastDFSInfoByCurr();
    if (muFile != null && muFile.getSize() != 0) {
        // ???
        if (!checkFileForSpringUpload(muFile)) {
            throw new RuntimeException("" + muFile.getOriginalFilename() + LOGGERINFO1);
        }
        // ???
        if (upConf != null && "1".equals(upConf.getUsedStatus())) {
            // ???
            if (null == fastdfs || "0".equals(fastdfs.getUserd())) {
                map = uploadImgUpyun.uploadForOldAndSmall(muFile, upConf);
            } else {
                // FastDFS
                map = uploadImgUpyun.uploadForOldAndSmall(muFile, upConf);
                map = uploadImgFastDFS.saveToFastDFS(map, fastdfs);
            }
        } else {
            // Java?
            // ??
            if (null == fastdfs || "0".equals(fastdfs.getUserd())) {
                map = uploadImgJava.uploadForOldAndSmall(muFile);
            } else {
                // FastDFS
                map = uploadImgJava.uploadForABCSizeSaveFastDFS(muFile);
                map = uploadImgFastDFS.saveToFastDFS(map, fastdfs);
            }
        }
        return map.get("oldimg");
    } else {
        return null;
    }
}

From source file:com.ylife.goods.model.UploadUtil.java

/**
 * key//from w  ww. j a va 2s .  com
 * 
 * @param muFile
 *            
 * @param request
 *            HttpServletRequest
 * @return Map  key{0,1,2,oldimg} 0? 1 2 oldimg 
 */
public static synchronized Map<String, String> uploadFile(MultipartFile muFile, HttpServletRequest request) {
    Map<String, String> map = new HashMap<String, String>();
    UpyunConf upConf = sysHelperMapper.selectUpyunConf();
    FastDFSInfo fastdfs = fastDFSService.getFastDFSInfoByCurr();

    if (muFile != null && muFile.getSize() != 0) {
        // ???
        if (!checkFileForSpringUpload(muFile)) {
            throw new RuntimeException("" + muFile.getOriginalFilename() + LOGGERINFO1);
        }
        // ???
        if (upConf != null && "1".equals(upConf.getUsedStatus())) {
            // ???
            if (null == fastdfs || "0".equals(fastdfs.getUserd())) {
                map = uploadImgUpyun.uploadForABCSize(muFile, upConf);
            } else {
                // FastDFS
                map = uploadImgUpyun.uploadForABCSize(muFile, upConf);
                map = uploadImgFastDFS.saveToFastDFS(map, fastdfs);
            }
        } else {
            // Java?
            // ??
            if (null == fastdfs || "0".equals(fastdfs.getUserd())) {
                map = uploadImgJava.uploadForABCSize(muFile);
            } else {
                // FastDFS
                map = uploadImgJava.uploadForABCSizeSaveFastDFS(muFile);
                map = uploadImgFastDFS.saveToFastDFS(map, fastdfs);
            }
        }

        return map;
    } else {
        return null;
    }
}

From source file:com.ylife.goods.model.UploadUtil.java

/**
 * ,?key//from   w  w w. ja v  a 2 s.  c  o  m
 * 
 * @param muFile
 *            
 * @param request
 *            HttpServletRequest
 * @return Map  key{width...,oldimg} oldimg 
 */
public static synchronized Map<String, String> uploadFileByWidth(MultipartFile muFile,
        HttpServletRequest request) {
    Map<String, String> map = new HashMap<String, String>();
    UpyunConf upConf = sysHelperMapper.selectUpyunConf();
    FastDFSInfo fastdfs = fastDFSService.getFastDFSInfoByCurr();
    if (muFile != null && muFile.getSize() != 0) {
        // ???
        if (!checkFileForSpringUpload(muFile)) {
            throw new RuntimeException("" + muFile.getOriginalFilename() + LOGGERINFO1);
        }
        // ???
        if (upConf != null && "1".equals(upConf.getUsedStatus())) {
            // ???
            if (null == fastdfs || "0".equals(fastdfs.getUserd())) {
                map = uploadImgUpyun.uploadForAllSize(muFile, upConf);
            } else {
                // FastDFS
                map = uploadImgUpyun.uploadForAllSize(muFile, upConf);
                map = uploadImgFastDFS.saveToFastDFS(map, fastdfs);
            }
        } else {
            // Java?
            // ??
            if (null == fastdfs || "0".equals(fastdfs.getUserd())) {
                map = uploadImgJava.uploadForAllSize(muFile);
            } else {
                // FastDFS
                map = uploadImgJava.uploadForABCSizeSaveFastDFSWidth(muFile);
                map = uploadImgFastDFS.saveToFastDFS(map, fastdfs);
            }
        }
        return map;
    } else {
        return null;
    }
}

From source file:feign.form.feign.spring.MultipartSupportService.java

@Override
public String upload3(MultipartFile file, String folder, String message) {
    return file.getOriginalFilename() + ":" + file.getContentType();
}

From source file:org.sakaiproject.imagegallery.integration.stub.FileLibraryStub.java

public ImageFile storeImageFile(MultipartFile sourceImageFile) {
    String filename = sourceImageFile.getOriginalFilename();
    String fileId = "/secretspot/image-gallery/" + contextService.getCurrentContextUid() + "/" + filename;
    ImageFile imageFile = new ImageFile();
    imageFile.setContentType(sourceImageFile.getContentType());
    imageFile.setDataUrl("http://localhost" + fileId);
    imageFile.setFileId(fileId);//from   www  .  j  ava 2 s . c  om
    imageFile.setFilename(filename);
    idsToFiles.put(fileId, imageFile);
    return imageFile;
}