org.springframework.web.multipart.MultipartFile.getSize()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(10.2k)|赞(0)|评价(0)|浏览(281)

本文整理了Java中org.springframework.web.multipart.MultipartFile.getSize()方法的一些代码示例,展示了MultipartFile.getSize()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MultipartFile.getSize()方法的具体详情如下:
包路径:org.springframework.web.multipart.MultipartFile
类名称:MultipartFile
方法名:getSize

MultipartFile.getSize介绍

[英]Return the size of the file in bytes.
[中]返回文件的大小(以字节为单位)。

代码示例

代码示例来源:origin: spring-projects/spring-framework

@Override
public long contentLength() {
  return this.multipartFile.getSize();
}

代码示例来源:origin: org.springframework/spring-web

@Override
public long contentLength() {
  return this.multipartFile.getSize();
}

代码示例来源:origin: BroadleafCommerce/BroadleafCommerce

@Override
public Blob createBlob(MultipartFile uploadedFile) throws IOException {
  return createBlob(uploadedFile.getInputStream(), uploadedFile.getSize());
}

代码示例来源:origin: linlinjava/litemall

@PostMapping("/upload")
public Object upload(@RequestParam("file") MultipartFile file) throws IOException {
  String originalFilename = file.getOriginalFilename();
  String url = storageService.store(file.getInputStream(), file.getSize(), file.getContentType(), originalFilename);
  Map<String, Object> data = new HashMap<>();
  data.put("url", url);
  return ResponseUtil.ok(data);
}

代码示例来源:origin: BroadleafCommerce/BroadleafCommerce

@Override
@Transactional(TransactionUtils.DEFAULT_TRANSACTION_MANAGER)
public StaticAsset createStaticAssetFromFile(MultipartFile file, Map<String, String> properties) {
  try {
    return createStaticAsset(file.getInputStream(), normalizeFileExtension(file), file.getSize(), properties);
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: linlinjava/litemall

@RequiresPermissions("admin:storage:create")
@RequiresPermissionsDesc(menu={"系统管理" , "对象存储"}, button="上传")
@PostMapping("/create")
public Object create(@RequestParam("file") MultipartFile file) throws IOException {
  String originalFilename = file.getOriginalFilename();
  String url = storageService.store(file.getInputStream(), file.getSize(), file.getContentType(), originalFilename);
  Map<String, Object> data = new HashMap<>();
  data.put("url", url);
  return ResponseUtil.ok(data);
}

代码示例来源:origin: hs-web/hsweb-framework

/**
 * ueditor上传文件
 *
 * @return 上传结果
 * @throws IOException 文件上传错误
 */
@RequestMapping(method = RequestMethod.POST, consumes = "multipart/form-data")
@ApiOperation("上传文件")
public String upload(@RequestParam(value = "upfile", required = false) MultipartFile file) throws IOException {
  String fileName = file.getOriginalFilename();
  String suffix = FileType.getSuffixByFilename(fileName);
  String path = fileService.saveStaticFile(file.getInputStream(), System.currentTimeMillis() + suffix);
  State state = new BaseState(true);
  state.putInfo("size", file.getSize());
  state.putInfo("title",fileName);
  state.putInfo("url", path);
  state.putInfo("type", suffix);
  state.putInfo("original",fileName);
  return state.toJSONString();
}

代码示例来源:origin: ZHENFENG13/My-Blog

for (MultipartFile multipartFile : multipartFiles) {
  String fname = multipartFile.getOriginalFilename();
  if (multipartFile.getSize() <= WebConst.MAX_FILE_SIZE) {
    String fkey = TaleUtils.getFileKey(fname);
    String ftype = TaleUtils.isImage(multipartFile.getInputStream()) ? Types.IMAGE.getType() : Types.FILE.getType();

代码示例来源:origin: spring-projects/spring-integration

@Override
public MultipartFile readMultipartFile(MultipartFile multipartFile) throws IOException {
  File upload = File.createTempFile(this.prefix, this.suffix, this.directory);
  multipartFile.transferTo(upload);
  UploadedMultipartFile uploadedMultipartFile = new UploadedMultipartFile(upload, multipartFile.getSize(),
      multipartFile.getContentType(), multipartFile.getName(), multipartFile.getOriginalFilename());
  if (logger.isDebugEnabled()) {
    logger.debug("copied uploaded file [" + multipartFile.getOriginalFilename() +
        "] to [" + upload.getAbsolutePath() + "]");
  }
  return uploadedMultipartFile;
}

代码示例来源:origin: zhangxd1989/springboot-dubbox

) {
  String path = "";
  if (photo != null && photo.getSize() > 0) {
    AuthUser user = WebUtils.getCurrentUser();
    FileIndex ufi = WebUtils.buildFileIndex(photo, TripUser.IMAGE_FOLDER);

代码示例来源:origin: tomoya92/pybbs

@PostMapping("/uploadAvatar")
public Result uploadAvatar(@RequestParam("file") MultipartFile file, HttpSession session) {
 long size = file.getSize();
 int uploadAvatarSizeLimit = Integer.parseInt(systemConfigService.selectAllConfig().get("upload_avatar_size_limit").toString());
 if (size > uploadAvatarSizeLimit * 1024 * 1024) return error("文件太大了,请上传文件大小在 " + uploadAvatarSizeLimit + "MB 以内");
 // 拿到上传后访问的url
 String url = fileUtil.upload(file, "avatar", "avatar/" + getUser().getUsername());
 if (url == null) return error("上传的文件不存在或者上传过程发生了错误,请重试一下");
 // 查询当前用户的最新信息
 User user = userService.selectById(getUser().getId());
 user.setAvatar(url);
 // 保存用户新的头像
 userService.update(user);
 // 将最新的用户信息更新在session里
 if (session != null) session.setAttribute("_user", user);
 return success(url);
}

代码示例来源:origin: sanluan/PublicCMS

fileComponent.upload(file, siteComponent.getWebFilePath(site, fileName));
logUploadService.save(new LogUpload(site.getId(), ControllerUtils.getAdminFromSession(session).getId(),
    LogLoginService.CHANNEL_WEB_MANAGER, originalName, LogUploadService.getFileType(suffix), file.getSize(),
    RequestUtils.getIpAddress(request), CommonUtils.getDate(), fileName));
Map<String, Object> map = getResultMap(true);
map.put("size", file.getSize());
map.put("title", originalName);
map.put("url", fileName);

代码示例来源:origin: sanluan/PublicCMS

fileComponent.upload(file, siteComponent.getWebFilePath(site, fileName));
logUploadService.save(new LogUpload(site.getId(), ControllerUtils.getAdminFromSession(session).getId(),
    LogLoginService.CHANNEL_WEB_MANAGER, originalName, LogUploadService.getFileType(suffix), file.getSize(),
    RequestUtils.getIpAddress(request), CommonUtils.getDate(), fileName));
Map<String, Object> map = getResultMap(true);
map.put("size", file.getSize());
map.put("title", originalName);
map.put("url", fileName);

代码示例来源:origin: sanluan/PublicCMS

fileComponent.upload(upload, siteComponent.getWebFilePath(site, fileName));
logUploadService.save(new LogUpload(site.getId(), ControllerUtils.getAdminFromSession(session).getId(),
    LogLoginService.CHANNEL_WEB_MANAGER, originalName, LogUploadService.getFileType(suffix), upload.getSize(),
    RequestUtils.getIpAddress(request), CommonUtils.getDate(), fileName));
Map<String, Object> map = getResultMap(true);

代码示例来源:origin: sanluan/PublicCMS

logUploadService.save(new LogUpload(site.getId(), ControllerUtils.getAdminFromSession(session).getId(),
    LogLoginService.CHANNEL_WEB_MANAGER, originalName,
    LogUploadService.getFileType(fileComponent.getSuffix(originalName)), file.getSize(),
    RequestUtils.getIpAddress(request), CommonUtils.getDate(), filePath));

代码示例来源:origin: sanluan/PublicCMS

logUploadService.save(new LogUpload(site.getId(), ControllerUtils.getAdminFromSession(session).getId(),
    LogLoginService.CHANNEL_WEB_MANAGER, originalName,
    LogUploadService.getFileType(fileComponent.getSuffix(originalName)), file.getSize(),
    RequestUtils.getIpAddress(request), CommonUtils.getDate(), filePath));

代码示例来源:origin: sanluan/PublicCMS

logUploadService.save(new LogUpload(site.getId(), ControllerUtils.getAdminFromSession(session).getId(),
    LogLoginService.CHANNEL_WEB_MANAGER, originalName, LogUploadService.getFileType(suffix),
    imgFile.getSize(), RequestUtils.getIpAddress(request), CommonUtils.getDate(), fileName));
Map<String, Object> map = getResultMap(true);
map.put(RESULT_URL, fileName);

代码示例来源:origin: sanluan/PublicCMS

logUploadService.save(new LogUpload(site.getId(), ControllerUtils.getAdminFromSession(session).getId(),
    LogLoginService.CHANNEL_WEB_MANAGER, originalName, LogUploadService.getFileType(suffix),
    imgFile.getSize(), RequestUtils.getIpAddress(request), CommonUtils.getDate(), fileName));
Map<String, Object> map = getResultMap(true);
map.put(RESULT_URL, fileName);

代码示例来源:origin: sanluan/PublicCMS

/**
 * @param file
 * @param _csrf
 * @param request
 * @param session
 * @param model
 * @return view name
 */
@RequestMapping(value = "doUploadLicense", method = RequestMethod.POST)
public String upload(MultipartFile file, String _csrf, HttpServletRequest request, HttpSession session, ModelMap model) {
  SysSite site = getSite(request);
  if (ControllerUtils.verifyCustom("noright", !siteComponent.isMaster(site.getId()), model)
      || ControllerUtils.verifyNotEquals("_csrf", ControllerUtils.getAdminToken(request), _csrf, model)) {
    return CommonConstants.TEMPLATE_ERROR;
  }
  if (null != file && !file.isEmpty()) {
    try {
      fileComponent.upload(file, siteComponent.getRootPath() + CommonConstants.LICENSE_FILENAME);
      logUploadService.save(new LogUpload(site.getId(), ControllerUtils.getAdminFromSession(session).getId(),
          LogLoginService.CHANNEL_WEB_MANAGER, "license.dat", LogUploadService.FILE_TYPE_OTHER, file.getSize(),
          RequestUtils.getIpAddress(request), CommonUtils.getDate(), CommonConstants.LICENSE_FILENAME));
      return CommonConstants.TEMPLATE_DONE;
    } catch (IllegalStateException | IOException e) {
      log.error(e.getMessage(), e);
    }
  }
  return CommonConstants.TEMPLATE_ERROR;
}

代码示例来源:origin: sanluan/PublicCMS

/**
 * @param file
 * @param _csrf
 * @param request
 * @param session
 * @param model
 * @return view name
 */
@RequestMapping(value = "doUploadLicense", method = RequestMethod.POST)
public String upload(MultipartFile file, String _csrf, HttpServletRequest request, HttpSession session, ModelMap model) {
  SysSite site = getSite(request);
  if (ControllerUtils.verifyCustom("noright", !siteComponent.isMaster(site.getId()), model)
      || ControllerUtils.verifyNotEquals("_csrf", ControllerUtils.getAdminToken(request), _csrf, model)) {
    return CommonConstants.TEMPLATE_ERROR;
  }
  if (null != file && !file.isEmpty()) {
    try {
      fileComponent.upload(file, siteComponent.getRootPath() + CommonConstants.LICENSE_FILENAME);
      logUploadService.save(new LogUpload(site.getId(), ControllerUtils.getAdminFromSession(session).getId(),
          LogLoginService.CHANNEL_WEB_MANAGER, "license.dat", LogUploadService.FILE_TYPE_OTHER, file.getSize(),
          RequestUtils.getIpAddress(request), CommonUtils.getDate(), CommonConstants.LICENSE_FILENAME));
      return CommonConstants.TEMPLATE_DONE;
    } catch (IllegalStateException | IOException e) {
      log.error(e.getMessage(), e);
    }
  }
  return CommonConstants.TEMPLATE_ERROR;
}

相关文章