package com.demo.controller;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import com.demo.util.Result;
/*
 * 内容
 */
@Controller
@RequestMapping("upload")
public class FileController {
/*	@Autowired
	private ContentMapper contentMapper;*/
	/*
	 * 上传视频 
	 * 如果要携带别的 参数 用 这个 格式  @RequestParam("recordId") Integer recordId,
	 * recordId 参数名字
	 */
	@RequestMapping(value="video") 
	@ResponseBody
	public Result uoloadVideo(@RequestParam("file") MultipartFile file,Model model,HttpServletRequest request, HttpServletResponse response) {
		Result result = new Result();
		Map<String, Object> data = new HashMap<String, Object>();
		String serverPath = "/upload/" + new SimpleDateFormat("yyyyMM").format(new Date()) + "/";
		String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort();
		String filePath = request.getSession().getServletContext().getRealPath(serverPath);
		String fileName = UUID.randomUUID().toString().replaceAll("-", "") + file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
		String fileUrl = request.getContextPath() + serverPath + fileName;
		File targetFile = new File(filePath, fileName);
		if (!targetFile.exists()) {
			targetFile.mkdirs();
		}
		try {
			file.transferTo(targetFile);
			
			data.put("fileUrl", basePath+fileUrl);
			result = new Result(0, "上传成功", data);
		} catch (Exception e) {
			result = new Result(1, "上传异常");
		}
		return result;
	
	}
	@RequestMapping(value="index") 
	public String index( ) {
		return "index";
		
	}
	
}
 最近下载更多
最近下载更多
                
                wen435301369     LV17
                2024年12月7日
            
            
        
                sjc199     LV2
                2022年6月13日
            
            
        
                13613768985     LV1
                2022年5月13日
            
            
        
                han329574     LV8
                2021年12月5日
            
            
        
                空空空     LV1
                2021年7月20日
            
            
        
                871505903     LV4
                2021年4月26日
            
            
        
                lktkitty     LV1
                2020年12月7日
            
            
        
                a770919458     LV1
                2020年10月29日
            
            
        
                无聊de人     LV1
                2020年7月27日
            
            
        
                yantingbin2012     LV1
                2020年7月13日
            
            
         最近浏览更多
最近浏览更多
                
                6418368     LV10
                8月4日
            
            
        
                s4dmcc     LV1
                2024年9月17日
            
            
        
                微信网友_7024101507420160     LV2
                2024年6月7日
            
            
        
                genyuan2014     LV6
                2024年4月30日
            
            
        
                hmf1989    
                2024年4月26日
            
            
                    暂无贡献等级
            
        
                15103432984     LV2
                2024年3月16日
            
            
        
                3334004690     LV11
                2024年3月6日
            
            
        
                pangzhihui     LV14
                2023年12月15日
            
            
        
                uni-code_0123     LV1
                2023年11月29日
            
            
        
                微信网友_6696101153525760    
                2023年10月17日
            
            
                    暂无贡献等级
            
        
 
                 
     
                