springboot取yum文件配置的参数

  • package com.bgxt.wechat.api.controller;

    import java.io.File;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.OutputStream;
    import java.util.HashMap;
    import java.util.Iterator;
    import java.util.List;
    import java.util.Map;

    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServletRequest;

    import org.apache.commons.fileupload.FileItem;
    import org.apache.commons.fileupload.disk.DiskFileItemFactory;
    import org.apache.commons.fileupload.servlet.ServletFileUpload;
    import org.apache.http.HttpEntity;
    import org.apache.http.HttpResponse;
    import org.apache.http.client.HttpClient;
    import org.apache.http.client.methods.HttpPost;
    import org.apache.http.entity.mime.MultipartEntity;
    import org.apache.http.entity.mime.content.FileBody;
    import org.apache.http.impl.client.DefaultHttpClient;
    import org.apache.http.util.EntityUtils;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.beans.factory.annotation.Value;
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestMethod;
    import org.springframework.web.bind.annotation.RequestParam;
    import org.springframework.web.bind.annotation.ResponseBody;
    import org.springframework.web.multipart.MultipartFile;

    import com.bgxt.chat.config.CommonConfiguration;
    import com.bgxt.wechat.config.FastDfsProperties;
    import com.bgxt.wechat.util.FastDFSUtils;
    import com.bgxt.wechat.util.JedisUtils;
    import com.google.common.collect.Maps;
    import org.springframework.core.env.Environment;


    import redis.clients.jedis.Jedis;


    @Controller
    @RequestMapping(value="/a/uploade/uploadeFile")
    public class UploadController {
        @Autowired
        private FastDfsProperties fp;
        
        @Autowired  
        private Environment env;
        
        @Value("${fdfs.resHost}")  
        private String resHost;
        
        @Value("${fdfs.storagePort}")  
        private String storagePort;
        
        @RequestMapping(value="/upload",method = RequestMethod.POST)
        @ResponseBody
        public Map upload(@RequestParam(required=false,value="uploadFile") MultipartFile uploadFile,HttpServletRequest request) throws Exception { 
            Jedis jedis = JedisUtils.getJedis();
            Map resultMap = Maps.newHashMap();
            if (uploadFile!=null&&!uploadFile.equals("")) {
               //String chatId=request.getParameter("chatId");
            String fileName =null;
            fileName = uploadFile.getOriginalFilename();
            String prefix=fileName.substring(fileName.lastIndexOf(".")+1);//PNG
            int i=1;
            String uploadeName="";
            long fileSzie = uploadFile.getSize()/1024;
            InputStream in = uploadFile.getInputStream();
            uploadeName=FastDFSUtils.uploadPic(in, fileName);
            String chatType="wechat";
            //jedis.publish(CommonConfiguration.redisCustomerToAgentChannelPrefix+"webchat", uploadeName);
            String resurl="http://"+env.getProperty("fdfs.resHost")+":"+env.getProperty("fdfs.storagePort")+"/";
            jedis.set("imageKey", "http://此处为服务器的ip地址:80/"+uploadeName);
            //System.out.println("http://"+resHost+":"+storagePort+"/");
            System.out.println();
            
            try {
                resultMap.put("fileSzie",fileSzie);
                resultMap.put("fileUrl","http://此处为服务器的ip地址:80/"+uploadeName);
                
            } finally {
                try {
                    in.close();
                } catch (Exception e) {
                    e.printStackTrace();
                    System.out.println("多媒体文件上传失败");
                }
            }
            }
            return resultMap;
        }  

        /**
         * 视频上传
         */
        @RequestMapping(value = "/uploadeVideo",method = RequestMethod.POST)
        @ResponseBody
        public Map uploadeVideo(@RequestParam(required=false,value="vuploadFile") MultipartFile vuploadFile,HttpServletRequest request)throws Exception {
            Jedis jedis = JedisUtils.getJedis();
            Map resultMap = Maps.newHashMap();
           if (vuploadFile!=null&&!vuploadFile.equals("")) {
            String fileName = vuploadFile.getOriginalFilename();
            String prefix=fileName.substring(fileName.lastIndexOf(".")+1);
            String fileOtherName=fileName.substring(0, fileName.length()-prefix.length()-1);//得到文件名。去掉了后缀
            int i=1;

           //log.info("连接ftp:{}:{}", f.getIpAddr(), f.getPort());
            String uploadeName="";
            long fileSzie = vuploadFile.getSize()/1024;
            InputStream in = vuploadFile.getInputStream();
            uploadeName=FastDFSUtils.uploadPic(in, fileName);
            String chatType="wechat";
            //jedis.publish(CommonConfiguration.redisCustomerToAgentChannelPrefix+"webchat", uploadeName);
            jedis.set("videoKey", "http://此处为服务器的ip地址:80/"+uploadeName);
           try {
                //resultMap.put("fileName",name+"."+prefix);
                resultMap.put("fileSzie",fileSzie);
                resultMap.put("fileUrl","http://此处为服务器的ip地址:80/"+uploadeName);
            } finally {
                try {
                    in.close();
                } catch (Exception e) {
                    e.printStackTrace();
                    System.out.println("视频文件上传失败");
                }
            }
        }
            return resultMap;
        }
        
        
        
    }

你可能感兴趣的:(springboot取yum文件配置的参数)