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


Java MultipartFile.getSize方法代码示例

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


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

示例1: add

import org.springframework.web.multipart.MultipartFile; //导入方法依赖的package包/类
public void add(Weaver weaver,MultipartFile data) { // 회원 추가 서비스
	Pass pass;
	if(weaverDao.existsWeaver())
		pass = new Pass("ROLE_USER"); 
	else
		pass = new Pass("ROLE_ADMIN"); // 최초 회원 가입시 운영자 지위
	weaver.addPass(pass);
	weaver.setPassword(passwordEncoder.encodePassword(weaver.getPassword(), null));
	
	if(data != null && data.getSize()>0)
		weaver.setData(dataDao.insert(new Data(new ObjectId(new Date()).toString(), data, weaver)));
	weaverDao.insert(weaver);	
	
	File file = new File(gitUtil.getGitPath() + weaver.getId());
	file.mkdir();
}
 
开发者ID:forweaver,项目名称:forweaver2.0,代码行数:17,代码来源:WeaverService.java

示例2: validate

import org.springframework.web.multipart.MultipartFile; //导入方法依赖的package包/类
public void validate(Object obj, Errors errors) {

        FileUpload fileUploadModel = (FileUpload) obj;
        MultipartFile file = fileUploadModel.getFile();
        if(file.isEmpty()){
            errors.rejectValue("file", "upload.file.required");
        }
        else if(!PNG_MIME_TYPE_PNG.equalsIgnoreCase(file.getContentType()) && !PNG_MIME_TYPE_JPEG.equalsIgnoreCase(file.getContentType())){
            errors.rejectValue("file", "upload.invalid.file.type");
        }

        else if(file.getSize() > A_MB_IN_BYTES){
            errors.rejectValue("file", "upload.exceeded.file.size");
        }

    }
 
开发者ID:Exercon,项目名称:AntiSocial-Platform,代码行数:17,代码来源:FileValidator.java

示例3: uploadAvatar

import org.springframework.web.multipart.MultipartFile; //导入方法依赖的package包/类
@ApiOperation("头像上传")
@PostMapping("/profile/avatar")
@RequiresAuthentication
public ResponseEntity uploadAvatar(@RequestParam("file") MultipartFile file) throws IOException {

    int uid = SessionHelper.get().getUid();

    if (file.getSize()/1000 > 2*1024) {
        throw new WebErrorException("文件过大");
    }

    if (! file.getContentType().equals("image/jpeg")) {
        throw new WebErrorException("文件格式非法");
    }
    String filePath = fileUtil.uploadAvatar(file.getInputStream(), "jpg");

    if (filePath == null) {
        throw new WebErrorException("文件上传失败");
    }

    int aid = attachmentService.add(uid, filePath);
    if (! userService.updateUserAvatar(uid, aid)) {
        throw new WebErrorException("头像更新失败");
    }
    return new ResponseEntity("头像更新成功");
}
 
开发者ID:Eagle-OJ,项目名称:eagle-oj-api,代码行数:27,代码来源:UserController.java

示例4: uploadNote

import org.springframework.web.multipart.MultipartFile; //导入方法依赖的package包/类
@RequestMapping(value = "/uploadNote")
@ResponseBody
public String uploadNote(@RequestParam(value = "uploadFile") MultipartFile uploadFile, @RequestParam(value = "notebookId") int notebookId, HttpSession session) throws IOException  {
     int userId = getUserId();
     JsonObject json = new JsonObject();

     if (uploadFile.getSize() > 0) {
         String leftPath = session.getServletContext().getRealPath("/temp/");
         String filename = uploadFile.getOriginalFilename();
         if (filename.endsWith("html")) {
             File file = new File(leftPath, filename);
             uploadFile.transferTo(file);
             createNoteService.uploadFileNote(userId, notebookId, file, new Date());
             file.delete();
             json.addProperty("result", "success");
         } else {
             json.addProperty("result", "wrongType");
         }
     } else {
         json.addProperty("result", "noFile");
     }
    return json.toString();
}
 
开发者ID:qinjr,项目名称:TeamNote,代码行数:24,代码来源:NoteController.java

示例5: isValidImage

import org.springframework.web.multipart.MultipartFile; //导入方法依赖的package包/类
public static String isValidImage(HttpServletRequest request, MultipartFile file){
    //最大文件大小
    long maxSize = 5242880;
    //定义允许上传的文件扩展名
    HashMap<String, String> extMap = new HashMap<String, String>();
    extMap.put("image", "gif,jpg,jpeg,png,bmp");

    if(!ServletFileUpload.isMultipartContent(request)){
        return "请选择文件";
    }

    if(file.getSize() > maxSize){
        return "上传文件大小超过5MB限制";
    }
    //检查扩展名
    String fileName=file.getOriginalFilename();
    String fileExt = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
    if(!Arrays.<String>asList(extMap.get("image").split(",")).contains(fileExt)){
        return "上传文件扩展名是不允许的扩展名\n只允许" + extMap.get("image") + "格式";
    }

    return "valid";
}
 
开发者ID:Exrick,项目名称:xmall,代码行数:24,代码来源:QiniuUtil.java

示例6: isValid

import org.springframework.web.multipart.MultipartFile; //导入方法依赖的package包/类
@Override
public boolean isValid(MultipartFile[] multipartFiles, ConstraintValidatorContext constraintValidatorContext) {
    long _totalSize = 0L;
    if (multipartFiles == null || multipartFiles.length <= 0) {
        return allowEmpty;
    }
    boolean result = false;
    for (MultipartFile multipartFile : multipartFiles) {
        result = (allowSize(multipartFile) && allowContentType(multipartFile));
        if (!result) {
            return false;
        }
        _totalSize += multipartFile.getSize();
    }
    /*
      totalSize = 0 ,则不限制
      如果超出大小,则限制
     */
    return totalSize == 0 || _totalSize < totalSize;
}
 
开发者ID:egzosn,项目名称:spring-jdbc-orm,代码行数:21,代码来源:MultipartFilesUploadValidate.java

示例7: put

import org.springframework.web.multipart.MultipartFile; //导入方法依赖的package包/类
/**
* <B>方法名称:</B>文件上传<BR>
* <B>概要说明:</B>文件上传<BR>
* @param key 键值
* @param type 类型
* @param userId 用户标识
* @param mf 文件对象	
* @param expired 过期时间
* @param descInfo 描述
* @return String 错误信息
* @throws Exception 输入输出异常
*/
  public JSONObject put(String key, String type, String userId, MultipartFile mf, Date expired, String descInfo) throws Exception {
      
  	String filename = mf.getOriginalFilename();
  	String extName = getExtName(filename);
  	String fileId = FastDFSClientUtils.upload(mf.getBytes(), extName);
  	String dataGroup = fileId.substring(0,fileId.indexOf("/"));
  	long bytes = mf.getSize();
  	
      SysFile file = new SysFile();
      file.setKey(key);
      file.setName(filename);
      file.setType(type);
      file.setExt(extName);
      file.setBytes(bytes);
      file.setDataPath(FASTDFS_BASEURL + fileId);
      file.setDataGroup(dataGroup);
      file.setExpired(expired);
      file.setDescInfo(descInfo);
      file.setUpdateBy(userId);
      sysFileComDao.insert(file);
      
      JSONObject ret = new JSONObject();
      ret.put("success", true);
      ret.put("key", key);
      ret.put("type", type);
      ret.put("name", mf.getOriginalFilename());
      ret.put("bytes", mf.getSize());
      ret.put("dataPath", FASTDFS_BASEURL + fileId);
      ret.put("dataGroup", dataGroup);
      ret.put("expired", expired);
      return ret;
  }
 
开发者ID:craware,项目名称:webapp-tyust,代码行数:45,代码来源:SysFileComService.java

示例8: update

import org.springframework.web.multipart.MultipartFile; //导入方法依赖的package包/类
public void update(Weaver weaver,String password,String newpassword,String say,MultipartFile data) { // 회원 수정
	// TODO Auto-generated method stub
	if(data != null && data.getSize() > 0) {
		dataDao.delete(weaver.getData());
		weaver.setData(dataDao.insert(new Data(new ObjectId(new Date()).toString(), data, weaver)));
	}

	if(this.validPassword(weaver,password) && newpassword != null && newpassword.length() > 3)
		weaver.setPassword(passwordEncoder.encodePassword(newpassword, null));

	if(say != null && !say.equals(""))
		weaver.setSay(say);

	weaverDao.update(weaver);
}
 
开发者ID:forweaver,项目名称:forweaver2.0,代码行数:16,代码来源:WeaverService.java

示例9: upload

import org.springframework.web.multipart.MultipartFile; //导入方法依赖的package包/类
@RequestMapping("upload/{id}")
public ExecuteResult<Boolean> upload(@RequestParam("file") MultipartFile[] multipartFiles, @PathVariable Long id)
		throws IOException {

	final ExecuteResult<Boolean> result = new ExecuteResult<>();
	
	try {
		for (MultipartFile file : multipartFiles) {
			String fileName = file.getOriginalFilename();
			if (file.getSize() > Constants.MAX_FILE_SIZE) {
				result.setSuccess(false);
				return result;
			}

			String realPath = new Date().getTime() + fileName.substring(fileName.lastIndexOf("."));
			String type = FileUtil.isImage(file.getInputStream()) ? Attach.UPLOAD_TYPE_IMAGE
					: Attach.UPLOAD_TYPE_FILE;
			File tempFile = new File(upload_dir + realPath);
			if (!tempFile.getParentFile().exists()) {
				tempFile.mkdirs();
			}
			FileCopyUtils.copy(file.getInputStream(), new FileOutputStream(tempFile));
			Attach attach = new Attach(id, fileName, type, realPath, new Date());
			attachDao.save(attach);
		}
		result.setSuccess(true);
	} catch (final Exception e) {
		result.setSuccess(false);
		result.setErrorCode(ErrorCode.EXCEPTION.name());
		logger.error("", e);
	}
	return result;
}
 
开发者ID:handexing,项目名称:pinkyLam-Blog-Server,代码行数:34,代码来源:FileController.java

示例10: DocumentContentVersion

import org.springframework.web.multipart.MultipartFile; //导入方法依赖的package包/类
public DocumentContentVersion(StoredDocument item, MultipartFile file, Blob data) {
    this.mimeType = file.getContentType();
    setOriginalDocumentName(file.getOriginalFilename());
    this.size = file.getSize();
    this.documentContent = new DocumentContent(this, data);
    this.storedDocument = item;
}
 
开发者ID:hmcts,项目名称:document-management-store-app,代码行数:8,代码来源:DocumentContentVersion.java

示例11: isValid

import org.springframework.web.multipart.MultipartFile; //导入方法依赖的package包/类
@Override
public boolean isValid(MultipartFile multipartFile, ConstraintValidatorContext constraintValidatorContext) {

    System.out.println(multipartFile.getContentType());
    if (multipartFile == null || multipartFile.getSize() == 0) {
        return allowEmpty;
    }

    return (allowSize(multipartFile) && allowContentType(multipartFile));

}
 
开发者ID:egzosn,项目名称:spring-jdbc-orm,代码行数:12,代码来源:SingleFileUploadValidate.java

示例12: UploadEntityImp

import org.springframework.web.multipart.MultipartFile; //导入方法依赖的package包/类
/**
 * 带文件大小限制的构造
 * 
 * @param file
 *            MultipartFile
 * @param maxSize2KB
 *            限制文件大小
 * @throws IOException
 */
public UploadEntityImp(MultipartFile file, long maxSizeByKB) throws MaxUploadSizeExceededException {

	this.file = file;

	if (file == null) {
		throw new NullPointerException("MultipartFil 不能为空!");
	}

	fileSizeByKB = file.getSize() / 1024;

	if (fileSizeByKB > maxSizeByKB) {
		throw new MaxUploadSizeExceededException(maxSizeByKB * 1024);
	}
	
	// 获取该文件的文件名
	originalFilename = file.getOriginalFilename();

	// 获取文件后缀
	fileSuffix = UploadUtil.getFileSuffix(originalFilename);
	if (fileSuffix == null || fileSuffix.length() == 0) {
		// 通过Mime类型获取文件类型
		fileSuffix = ContentTypeUtil.getFileTypeByMimeType(file.getContentType());
	}

	// 创建文件名
	filename = UploadUtil.getFileName();


}
 
开发者ID:ZiryLee,项目名称:FileUpload2Spring,代码行数:39,代码来源:UploadEntityImp.java

示例13: createContent

import org.springframework.web.multipart.MultipartFile; //导入方法依赖的package包/类
@PostMapping("/objects")
@Timed
public ResponseEntity<String> createContent(@RequestParam(required = false) Integer size,
    @RequestParam("file") MultipartFile multipartFile)
    throws URISyntaxException {
    if (multipartFile.getSize() > applicationProperties.getMaxAvatarSize()) {
        throw new BusinessException(ERR_VALIDATION,
            "Avatar file must not exceed " + applicationProperties.getMaxAvatarSize() + " bytes");
    }
    String result = storageRepository.store(multipartFile, size);
    return ResponseEntity.ok(result);
}
 
开发者ID:xm-online,项目名称:xm-ms-entity,代码行数:13,代码来源:StorageResource.java

示例14: arrangement

import org.springframework.web.multipart.MultipartFile; //导入方法依赖的package包/类
@ResponseBody
@RequestMapping("/arrangement")
public CommonResult arrangement(MultipartFile multipartFile, Homework homework, HttpSession session) {
    if (multipartFile == null)
        return new CommonResult("文件为空", false);
    else if (homework.getCourseClassId() == null)
        return new CommonResult("班级为空", false);
    else if (!FileFormatUtils.isPackage(multipartFile.getOriginalFilename()))
        return new CommonResult("文件格式不是压缩包", false);
    else if (multipartFile.getSize() > FILE_SIZE)
        return new CommonResult("文件大小超出限制", false);
    else if (StringUtils.isEmpty(homework.getHomeworkName(), homework.getContent()))
        return new CommonResult("作业名称或正文不能为空", false);
    else {
        if (homework.getHomeworkName().length() > TITLE_SIZE) {
            if (homework.getContent().length() > CONTENT_SIZE)
                return new CommonResult("作业名称和正文太长", false);
            else
                return new CommonResult("作业名称太长", false);
        } else if (homework.getContent().length() > CONTENT_SIZE)
            return new CommonResult("正文太长", false);
    }

    User user = (User)session.getAttribute("user");
    homework.setAnnouncerId(user.getId());
    if (homeworkService.arrangement(homework, multipartFile)) {
        return new CommonResult("成功", true);
    } else
        return new CommonResult("添加作业失败", false);
}
 
开发者ID:Topview-us,项目名称:school-website,代码行数:31,代码来源:HomeworkController.java

示例15: doPost

import org.springframework.web.multipart.MultipartFile; //导入方法依赖的package包/类
public void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, java.io.IOException {
  // Check that we have a file upload request
  boolean isMultipart = ServletFileUpload.isMultipartContent(request);
  if (!isMultipart) {
    return;
  }
  try {
    MultipartHttpServletRequest
        multiRequest =
        new CommonsMultipartResolver().resolveMultipart(request);
    MultiValueMap<String, MultipartFile> fileMap = multiRequest.getMultiFileMap();
    BlobstoreService blobstoreService = AppFactory.get().getBlobstoreService();
    Map<String, String> names = new HashMap<>(1);
    for (String fieldName : fileMap.keySet()) {
      MultipartFile file = fileMap.getFirst(fieldName);
      String fileName = file.getOriginalFilename();
      String contentType = file.getContentType();
      long sizeInBytes = file.getSize();
      String
          blobKey =
          blobstoreService.store(fileName, contentType, sizeInBytes, file.getInputStream());
      names.put(fieldName, blobKey);
      names.put("file", fileName);

    }
    response.getWriter().write(new Gson().toJson(names));
    response.setStatus(HttpStatus.SC_CREATED);
  } catch (Exception ex) {
    _logger.severe("Upload failed", ex);
  }
}
 
开发者ID:logistimo,项目名称:logistimo-web-service,代码行数:33,代码来源:DirectFileUploadServlet.java


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