上传音频

/**
  * 添加音频素材
  * @param mapping
  * @param myform
  * @param request
  * @param response
  * @return
  * @throws Exception
  * @throws Exception
  */
 private String addMusic(ActionMapping mapping, ElementForm myform,
   HttpServletRequest request, HttpServletResponse response) throws Exception {
  AdvertiserPo user = (AdvertiserPo)request.getSession().getAttribute("user");
  String users=user.getAccount();//得到用户名
  if(users!=null&&users.length()>0){
   String fileType="music";// 上传的素材类型
   String serialString = Tools.getTimeSerial(); // 时间序列号
//   得到相对路径
   String dirPath="/uploadfile/" + users + "/" + fileType + "/"+serialString;
   ServletContext sc=request.getSession().getServletContext();
   //得到绝对路径
   String realPath=sc.getRealPath(dirPath);
             try {
    Hashtable files = myform.getMultipartRequestHandler().getFileElements();

    for (Map.Entry<String, FormFile> entry : (Set<Map.Entry<String, FormFile>>) (files
      .entrySet())) {
     FormFile musicFile = entry.getValue();
     // 判断文件是否为空
     if (musicFile != null && musicFile.getFileName().length() > 0) {
      // 上传文件
      UploadTool.uploadFile(realPath, musicFile);

      // 得到文件名称
      String musicRealityName = musicFile.getFileName().substring(0,
        musicFile.getFileName().lastIndexOf("."));
      
      // 添加到素材库
      AffixPoElement apElement = new AffixPoElement();
      apElement.setId(Tools.getNewID()); // 一个由时间组成的18位序列号
      apElement.setAffixType(fileType); // 文件类型
      apElement.setUserId(users); // 用户名
      apElement.setPath(dirPath); // 文件的相对路径
      apElement.setFileName(musicFile.getFileName()); // 文件名
      apElement.setRealityName(musicRealityName);
      apElement.setUploadDate(new Date());
      this.baseService.save(apElement);
     }
    }
    request.setAttribute("successInfo", "音频素材上传成功!");
    return "success";
   } catch (Exception e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    request.setAttribute("errorInfo", "音频素材上传失败");
    return "errror";
   }
   
  }else
  {
   request.setAttribute("errorInfo","您还没有登录");
   return "error";
  }
 }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值