NutzCN Logo
短点 上传例子_23c637ff
发布于 2992天前 作者 明天会吹什么风 2781 次浏览 复制 上一个帖子 下一个帖子
标签:

查看完整内容

    /**
     * 文件上传
     *
     * @param uploadFile
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/upload", method = RequestMethod.POST)
    public AjaxReturn uploadAttachFile(@RequestParam("feedbackfile") MultipartFile uploadFile) {
        AjaxReturn result = Ajax.fail();
        if (!uploadFile.isEmpty()) {

            JSONObject fileJson = new JSONObject();
            fileJson.put("fileRealName", uploadFile.getOriginalFilename());
            String fileSuffix = FilenameUtils.getExtension(uploadFile.getOriginalFilename());
            fileJson.put("fileSuffix", fileSuffix);
            fileJson.put("fileSize", uploadFile.getSize());
            fileJson.put("fileType", uploadFile.getContentType());

            String fileStoreName = System.currentTimeMillis() + String.valueOf(RandomUtils.nextInt(10000, 99999)) + "." + fileSuffix;
            fileJson.put("fileStoreName", fileStoreName);
            fileJson.put("fileStorePath", uploadStorePath);

            boolean isUploadOk = false;
            try {
                uploadFile.transferTo(new File(uploadStorePath + SystemUtils.FILE_SEPARATOR + fileStoreName));
                isUploadOk = true;
            } catch (IOException e) {
                log.error("upload feekback file error:{}", e.toString());
            }
            result.setOk(isUploadOk).setData(fileJson);
        }
        return result;
    }
0 回复
添加回复
请先登陆
回到顶部