浏览代码

图片上传接口

hzp 8 年之前
父节点
当前提交
5f4f6c9b3a

+ 8 - 8
patient-co-wlyy/src/main/java/com/yihu/wlyy/util/fastdfs/FastDFSUtil.java

@ -1,5 +1,6 @@
package com.yihu.wlyy.util.fastdfs;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.InetSocketAddress;
@ -51,7 +52,7 @@ public class FastDFSUtil {
//        }
//    }
    final static int BUFFER_SIZE = 4096;
    /**
     * 以输入流的方式上传文件
@ -90,14 +91,13 @@ public class FastDFSUtil {
            ObjectMapper objectMapper = new ObjectMapper();
            ObjectNode message = objectMapper.createObjectNode();
            byte fileBuffer[] = new byte[in.available()];
            int len = 0;
            int temp = 0;                             //所有读取的内容都使用temp接收
            while ((temp = in.read()) != -1) {            //当没有读取完时,继续读取
                fileBuffer[len] = (byte) temp;
                len++;
            ByteArrayOutputStream swapStream = new ByteArrayOutputStream();
            byte[] buff = new byte[BUFFER_SIZE]; //buff用于存放循环读取的临时数据
            int rc = 0;
            while ((rc = in.read(buff, 0, BUFFER_SIZE)) > 0) {
                swapStream.write(buff, 0, rc);
            }
            in.close();
            byte[] fileBuffer = swapStream.toByteArray(); //in_b为转换之后的结果
            TrackerServer trackerServer = FastDFSClientPool.getInstance().getTrackerServer();

+ 4 - 9
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/archives/PatientArchivesController.java

@ -180,21 +180,16 @@ public class PatientArchivesController extends WeixinBaseController {
    @RequestMapping(value = "/event/uploadImg", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation("单张上传图片")
    public String uploadImg(@ApiParam(name="mediaId",value="微信图片标识",defaultValue = "")
                            @RequestParam(value="mediaId",required = true) String mediaId,
                            @ApiParam(name="fileExt",value="文件格式后缀",defaultValue = "")
                            @RequestParam(value="fileExt",required = false) String fileExt)
    public String uploadImg(@ApiParam(name="mediaId",value="微信图片标识",defaultValue = "wL1vfE9g1fiRCl5xd-Xotl1XycWQ9mwigDLUv-S0Kmde-pXNrlySKbf5RM5SwwFl")
                            @RequestParam(value="mediaId",required = true) String mediaId)
    {
        try {
            String url ="";
            FastDFSUtil fastDFSUtil = new FastDFSConfig().fastDFSUtil();
            InputStream wxImg = getInputStream(mediaId);
            if(StringUtils.isEmpty(fileExt))
            {
                fileExt="jpg";
            }
            ObjectNode result = fastDFSUtil.upload(wxImg, fileExt, "");
            ObjectNode result = fastDFSUtil.upload(wxImg, "jpg", "");
            wxImg.close();
            if (result != null) {
                url = result.get("fileUrl").toString().replaceAll("\"", "");
            }