当前位置: 首页>>代码示例>>Java>>正文


Java MultipartFile.isEmpty方法代码示例

本文整理汇总了Java中org.springframework.web.multipart.MultipartFile.isEmpty方法的典型用法代码示例。如果您正苦于以下问题:Java MultipartFile.isEmpty方法的具体用法?Java MultipartFile.isEmpty怎么用?Java MultipartFile.isEmpty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.web.multipart.MultipartFile的用法示例。


在下文中一共展示了MultipartFile.isEmpty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: store

import org.springframework.web.multipart.MultipartFile; //导入方法依赖的package包/类
@Override
public void store(MultipartFile file) {
    String filename = StringUtils.cleanPath(file.getOriginalFilename());
    try {
        if (file.isEmpty()) {
            throw new UploadException("Failed to store empty file " + filename);
        }
        if (filename.contains("..")) {
            // This is a security check
            throw new UploadException(
                    "Cannot store file with relative path outside current directory "
                            + filename);
        }
        Files.copy(file.getInputStream(), this.rootLocation.resolve(filename),
                StandardCopyOption.REPLACE_EXISTING);
    } catch (IOException e) {
        throw new UploadException("Failed to store file " + filename, e);
    }
}
 
开发者ID:itdl,项目名称:AIweb,代码行数:20,代码来源:UploadKaServiceImpl.java

示例2: upload

import org.springframework.web.multipart.MultipartFile; //导入方法依赖的package包/类
/**
 * 上传文件.
 * @param request 请求
 * @param paraName 文件参数名
 * @param baseDir 基本目录
 * @param dir 文件相对目录
 * @return 文件名
 * @throws IOException IO异常
 */
public static List<String> upload(HttpServletRequest request, String paraName, String baseDir, String dir) throws IOException {
    List<String> fileNames = null;
    if (request instanceof MultipartHttpServletRequest) {
        List<MultipartFile> files = ((MultipartHttpServletRequest) request).getFiles(paraName);
        fileNames = new ArrayList<>(files.size());
        String originalName;
        String newName;
        for (MultipartFile file : files) {
            if (file.isEmpty()) {
                continue;
            }
            File dic = new File(baseDir + dir);
            if (!dic.exists()) {
                dic.mkdirs();
            }
            originalName = file.getOriginalFilename();
            newName = UUIDGenerator.getFileName() + originalName.substring(originalName.lastIndexOf("."));
            Files.copy(file.getInputStream(), Paths.get(baseDir + dir + "/" + newName));
            fileNames.add(dir + "/" + newName);
        }
    }
    return fileNames;
}
 
开发者ID:DomKing,项目名称:springbootWeb,代码行数:33,代码来源:UploadUtil.java

示例3: writeMultipartFile

import org.springframework.web.multipart.MultipartFile; //导入方法依赖的package包/类
private static File writeMultipartFile(MultipartFile multipartFile) {

		File file = null;

		try {
			if (!multipartFile.isEmpty()) {

				String multipartFileName = multipartFile.getOriginalFilename();
				String prefix = FilenameUtils.getBaseName(multipartFileName);
				String suffix = FilenameUtils.getExtension(multipartFileName);
				file = File.createTempFile(prefix, suffix);

				FileUtils.writeByteArrayToFile(file, multipartFile.getBytes());
			}
		}
		catch (Exception e) {
			LOG.error(e.getMessage(), e);
		}

		return file;
	}
 
开发者ID:chrisipa,项目名称:cloud-portal,代码行数:22,代码来源:VirtualMachineController.java

示例4: save

import org.springframework.web.multipart.MultipartFile; //导入方法依赖的package包/类
@SuppressWarnings("WeakerAccess")
public void save(MultipartFile multipartFile, String path) {
    if (multipartFile == null || multipartFile.isEmpty()) {
        throw new IllegalArgumentException("Multipart file is required.");
    }

    String contentType = multipartFile.getContentType();
    validateFormat(contentType);
    validateSize(multipartFile.getSize());

    try {
        doSave(multipartFile, path, contentType);
    } catch (IOException e) {
        LOGGER.error("Save image failed.", e);
        throw new RuntimeException(e);
    }
}
 
开发者ID:comHpf,项目名称:authcent,代码行数:18,代码来源:ImageUtil.java

示例5: update

import org.springframework.web.multipart.MultipartFile; //导入方法依赖的package包/类
/**
 * 更新用户信息
 * @param person
 * @param session
 * @return
 */
@PostMapping("/update")
public ServerResponse update(Person person,MultipartFile avatarFile,HttpSession session){
    if(person.getName().isEmpty()||person.getPwd().isEmpty()){
        return ServerResponse.createErrorResponse(400,"Name or Pwd is null.");
    }
    if(!checkLogin(session)){
        return ServerResponse.createErrorResponse(401,"Login Please.");
    }
    if(!avatarFile.isEmpty()){
        ServerResponse serverResponse=upload(avatarFile);
        if(serverResponse.getStatus()!=200){
            return serverResponse;
        }else{
            person.setAvatar((String) serverResponse.getData());
        }
    }
    return personService.updatePerson(person);
}
 
开发者ID:ju5t1nhhh,项目名称:personspringclouddemo,代码行数:25,代码来源:PersonController.java

示例6: extractMetadata

import org.springframework.web.multipart.MultipartFile; //导入方法依赖的package包/类
/**
 * Given a MultipartFile, extract the required metadata information for a RequestDocument in order to be used
 * in filesystem storage, database storage and email text
 */
@Override
public RequestDocument extractMetadata(MultipartFile file) {
    if (null == file || file.isEmpty()) {
        logger.warn("null file given to extract metadata from");

        return null;
    }

    String fullName = file.getOriginalFilename(); // full name - including extension (docFormat)
    String extension = fullName.substring(fullName.lastIndexOf('.')); // doc, pdf, etc
    String fileName = fullName.substring(0, fullName.lastIndexOf('.')); // without extension

    RequestDocument requestDocument = new RequestDocument();
    requestDocument.setFilename(fileName);
    requestDocument.setExtension(extension);
    requestDocument.setFullName(fullName);
    // other fields will be completed depending on the scope

    return requestDocument;
}
 
开发者ID:CoruptiaUcide,项目名称:va-vedem-api,代码行数:25,代码来源:StorageServiceImpl.java

示例7: uploadFile

import org.springframework.web.multipart.MultipartFile; //导入方法依赖的package包/类
public static String uploadFile(MultipartFile file) throws IOException {
    if (!file.isEmpty()) {
        String today = LocalDate.now().toString();

        String type = file.getContentType();
        String suffix = "." + type.split("/")[1];
        String userUploadPath = today + "/";
        String fileName = UUID.randomUUID().toString()+suffix;
        File file_dir = new File(Constants.UPLOAD_PATH + userUploadPath);
        if (!file_dir.exists()) file_dir.mkdirs();

        BufferedOutputStream stream = new BufferedOutputStream(new FileOutputStream(new File(Constants.UPLOAD_PATH + userUploadPath + fileName)));
        stream.write(file.getBytes());
        stream.close();

        return Constants.STATIC_URL+userUploadPath+fileName;
    }
    return null;
}
 
开发者ID:ChinaLHR,项目名称:JavaQuarkBBS,代码行数:20,代码来源:FileUtils.java

示例8: uploadFile

import org.springframework.web.multipart.MultipartFile; //导入方法依赖的package包/类
public boolean uploadFile(Picture picture, MultipartFile file) {

        if (!file.isEmpty())
            try {
                byte[] bytes = file.getBytes();
                File dir = new File(picture.getPath());
                if (!dir.exists())
                    dir.mkdirs();

                File serverFile = new File(dir.getAbsolutePath() + "\\" + picture.getName() + picture.getFileType());
                BufferedOutputStream stream = new BufferedOutputStream(new FileOutputStream(serverFile));

                stream.write(bytes);
                stream.close();
                return true;
            } catch (Exception e) {
                return false;
            }

        return false;
    }
 
开发者ID:xSzymo,项目名称:Spring-web-shop-project,代码行数:22,代码来源:PictureOperations.java

示例9: upload

import org.springframework.web.multipart.MultipartFile; //导入方法依赖的package包/类
/**
 * 上传文件
 */
@RequestMapping("/upload")
@RequiresPermissions("sys:oss:all")
public R upload(@RequestParam("file") MultipartFile file) throws Exception {
	if (file.isEmpty()) {
		throw new RRException("上传文件不能为空");
	}

	//上传文件
	String url = OSSFactory.build().upload(file.getBytes());

	//保存文件信息
	SysOssEntity ossEntity = new SysOssEntity();
	ossEntity.setUrl(url);
	ossEntity.setCreateDate(new Date());
	sysOssService.save(ossEntity);

	return R.ok().put("url", url);
}
 
开发者ID:zhaoqicheng,项目名称:renren-fast,代码行数:22,代码来源:SysOssController.java

示例10: handleAndroidFile

import org.springframework.web.multipart.MultipartFile; //导入方法依赖的package包/类
private void handleAndroidFile(CredentialDetail detail, MultipartFile file) throws IOException {
    if (!(detail instanceof AndroidCredentialDetail)) {
        return;
    }

    if (file == null || file.isEmpty()) {
        return;
    }

    AndroidCredentialDetail androidDetail = (AndroidCredentialDetail) detail;
    String extension = Files.getFileExtension(file.getOriginalFilename());

    if (!ANDROID_EXTENSIONS.contains(extension)) {
        throw new IllegalParameterException("Illegal android cert file");
    }

    String destFileName = getFileName(file.getOriginalFilename());
    Path destPath = credentailFilePath(destFileName);

    file.transferTo(destPath.toFile());
    androidDetail.setFile(new FileResource(file.getOriginalFilename(), destPath.toString()));
}
 
开发者ID:FlowCI,项目名称:flow-platform,代码行数:23,代码来源:CredentialController.java

示例11: update

import org.springframework.web.multipart.MultipartFile; //导入方法依赖的package包/类
@RequestMapping(value="/{codeID}/{rePostID}/update", method = RequestMethod.POST)
public String update(@PathVariable("codeID") int codeID, @PathVariable("rePostID") int rePostID,HttpServletRequest request,Model model) throws UnsupportedEncodingException {

	final MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest) request;
	final Map<String, MultipartFile> files = multiRequest.getFileMap();
	ArrayList<Data> datas = new ArrayList<Data>();
	Code code = this.codeService.get(codeID,true);
	RePost rePost = this.rePostService.get(rePostID);
	String content = request.getParameter("content");
	Weaver weaver = this.weaverService.getCurrentWeaver();
	String remove = request.getParameter("remove");
	if(code == null || rePost == null || content.length() < 5 ||
			rePost.getOriginalCode().getCodeID() != code.getCodeID()){
		model.addAttribute("say", "잘못 입력하셨습니다!!!");
		model.addAttribute("url", "/code/"+codeID);
		return "/alert";
	}

	if(!rePost.getWriter().equals(weaver) &&
			!this.tagService.validateTag(code.getTags(),weaver)){ // 태그에 권한이 없을때
		model.addAttribute("say", "권한이 없습니다!!!");
		model.addAttribute("url", "/code/"+codeID);
		return "/alert";
	}

	for (MultipartFile file : files.values())
		if(!file.isEmpty()){
			String fileID= this.dataService.getObjectID(file.getOriginalFilename(), weaver);
			if(!fileID.equals(""))
				datas.add(new Data(fileID,file,weaver));
		}

	rePost.setContent(content);
	this.rePostService.update(rePost,datas,remove.split("@"));

	return "redirect:/code/"+codeID;
}
 
开发者ID:forweaver,项目名称:forweaver2.0,代码行数:38,代码来源:CodeController.java

示例12: updateLogo

import org.springframework.web.multipart.MultipartFile; //导入方法依赖的package包/类
public void updateLogo(MultipartHttpServletRequest multipartReq, App app) throws IOException,
        MalformedURLException, URISyntaxException {
    int id = app.getId();
    // logo. 浏览器上传用户本地文件 或 下载远端服务器 图片.
    String logoUrlBak = multipartReq.getParameter("oldLogoUrl");// app.getLogoUrl();
    boolean needToDeleteLogoUrlBak = false;
    String remoteLogoUrl = multipartReq.getParameter("remoteLogoUrl");
    MultipartFile file = multipartReq.getFile("logoFile");
    String logoSubPath = null;
    if (file != null && !file.isEmpty()) {
        logoSubPath = attachmentService.saveFile(id, file);
    } else if (StringUtils.isNotBlank(remoteLogoUrl)) {
        // 拉取图片.
        logoSubPath = attachmentService.saveFile(id, remoteLogoUrl);
    }
    if (StringUtils.isNotBlank(logoSubPath)) {
        String logoUrl = PathUtils.concate(appConfig.getDestUploadBaseurl(), logoSubPath);
        app.setLogoUrl(logoUrl);
        saveOrUpdate(app);
        needToDeleteLogoUrlBak = true;
    }
    if (StringUtils.isNotBlank(logoUrlBak) && needToDeleteLogoUrlBak) {
        attachmentService.deleteFile(logoUrlBak);
    }

    appHistory4IndexDao.saveOrUpdate(app.getId());
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:28,代码来源:AppServiceImpl.java

示例13: store

import org.springframework.web.multipart.MultipartFile; //导入方法依赖的package包/类
@Override
public void store(MultipartFile file) {
    try {
        if (file.isEmpty()) {
            throw new StorageException("Failed to store empty file " + file.getOriginalFilename());
        }
        Files.copy(file.getInputStream(), this.rootLocation.resolve(file.getOriginalFilename()));
    } catch (IOException e) {
        throw new StorageException("Failed to store file " + file.getOriginalFilename(), e);
    }
}
 
开发者ID:Yuiffy,项目名称:file-download-upload-zip-demo,代码行数:12,代码来源:FileSystemStorageService.java

示例14: storeFile

import org.springframework.web.multipart.MultipartFile; //导入方法依赖的package包/类
private void storeFile(MultipartFile file, String filename, String ruleFilename, Path rootLocation) throws SystemException {
    try {
        if (file.isEmpty()) {
            throw  new SystemException("Failed to store empty file " + filename);
        }
        Files.copy(file.getInputStream(), rootLocation.resolve(ruleFilename));
    } catch (IOException e) {
        throw new SystemException("Failed to store file " + filename, e);
    }
}
 
开发者ID:realxujiang,项目名称:itweet-boot,代码行数:11,代码来源:StorageServiceImpl.java

示例15: asBytes

import org.springframework.web.multipart.MultipartFile; //导入方法依赖的package包/类
private byte[] asBytes(MultipartFile template) {
    if (template.isEmpty()) {
        throw new InvalidArgumentException("Received an empty template file");
    }
    try {
        return template.getBytes();
    } catch (IOException e) {
        throw new InvalidArgumentException(e);
    }
}
 
开发者ID:hmcts,项目名称:cmc-pdf-service,代码行数:11,代码来源:PDFGenerationEndpoint.java


注:本文中的org.springframework.web.multipart.MultipartFile.isEmpty方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。