zoukankan      html  css  js  c++  java
  • 文件上传:简单的demo

    /*
    接收前台传来的视频,把视频放到服务器中,并把视频地址保存到数据库
    */
    @RequestMapping(value = "/vms/media_main/saveVideo.do")
    public void saveVideo(@RequestParam("file")CommonsMultipartFile file, HttpServletRequest req, HttpServletResponse res) {

    Videoinfo videoinfo = new Videoinfo();
    String date = DateUtil.dateToString("yyyyMMdd",new Date());
    String path = "/home/nginx/vod/videos/upload/"+date+"/"+username;
    String name = file.getOriginalFilename(); //上传时的文件名
    int k = name.lastIndexOf(".");
    String videoname = name.substring(0,k);
    String format = name.substring(k+1).toUpperCase();//获取文件类型
    Date date1 = new Date();
    SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    //创建一个图片名字
    String fileName = new Date().getTime()+(int)(Math.random()*100)+name.substring(name.lastIndexOf("."));
    InputStream is;
    OutputStream os;
    String video = "" ;
    try {
    is = file.getInputStream();
    File paths = new File(path);
    if (!paths.exists()) {
    paths.mkdirs();
    }
    os = new FileOutputStream(new File(path,fileName));
    int len = 0;
    byte[] buffer = new byte[400];
    while((len=is.read(buffer))!=-1){
    os.write(buffer,0,len);
    }
    os.close();
    is.close();

    video = "videos/upload/"+date+"/"+username+"/"+fileName;

    videoinfo.setPath(video);
    videoinfo.setFormat(format);
    videoinfo.setVideoname(videoname);
    videoinfo.setCreatetime(format1.format(date1));
    videoinfo.setStatus(1);
    videoService.addSave(videoinfo);

    } catch (Exception e) {
    e.printStackTrace();
    }
    }
    <form action="" enctype="multipart/form-data" method="post">
     上传文件:<input type="file" name="file"><br/> 
    <input type="submit" value="提交"> 
    </form>
  • 相关阅读:
    深度学习模型调参
    人脸神经网络及算法整理
    【转】python pip install指定国内源
    人脸识别数据集整理
    卷积神经网络整理+ResNet50
    【转载】人脸检测通用评价标准
    【转载】InsightFace算法学习
    Linux手动识别4G模块
    openwrt监控程序(守护进程)
    测试流程详解
  • 原文地址:https://www.cnblogs.com/jietz0407-com/p/6494166.html
Copyright © 2011-2022 走看看