All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.xiushang.common.upload.controller.UploadController Maven / Gradle / Ivy

package com.xiushang.common.upload.controller;

import com.xiushang.common.upload.service.UploadService;
import com.xiushang.common.upload.vo.UploadBase64;
import com.xiushang.common.upload.vo.UploadBean;

import com.xiushang.framework.log.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import java.util.Map;


/**
 * 上传文件
 * @author liukefu
 */
@Api(tags = "文件上传")
@Controller
@RequestMapping(value = "/api/public",
        produces = "application/json; charset=UTF-8")
public class UploadController{
    @Autowired
    private UploadService uploadService;
    /**
     * 上传文件
     * @param request
     * @param userPath  在temp 下自定义一个目录
     * @return
     */
    @ApiOperation(value = "上传文件")
    @ResponseBody
    @PostMapping("/upload")
    public CommonResult> upload(HttpServletRequest request, @ApiParam(value = "上传根路径 
(指定上传文件存放的文件夹)",required = true) String userPath) { MultipartHttpServletRequest mulRequest = (MultipartHttpServletRequest) (request); List list = uploadService.upload(mulRequest,userPath); return CommonResult.success(list); } /** * 上传base64格式的文件 * @param uploadBase64 * @return */ @ApiOperation(value = "上传文件base64") @ResponseBody @PostMapping("/uploadBase64") public CommonResult> uploadBase64(@RequestBody UploadBase64 uploadBase64) { List list = uploadService.uploadBase64(uploadBase64); return CommonResult.success(list); } @ApiOperation(value = "上传大文件") @ResponseBody @PostMapping("/uploadBig") public CommonResult uploadBig(HttpServletRequest request,String userPath,String md5, Long size, Integer chunks, Integer chunk) { MultipartHttpServletRequest mulRequest = (MultipartHttpServletRequest) (request); Map fileMap = mulRequest.getFileMap(); Iterator it = fileMap.keySet().iterator(); UploadBean uploadBean = new UploadBean(); if (it.hasNext()) { String key = it.next(); uploadBean.setKey(key); uploadBean.setUserPath(userPath); MultipartFile multipartFile = fileMap.get(key); try { uploadService.uploadWithBlock(uploadBean, md5, size, chunks, chunk,multipartFile); } catch (IOException e) { e.printStackTrace(); } } return CommonResult.success(uploadBean); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy