发表于: 2017-11-17 23:36:00

1 696


今天完成的事情:

完成图片上传工具类.

   public String upImage( MultipartFile file, String userName) {
//如果是Windows情况下,格式是 D:\\qiniu\\test.png
//        String localFilePath = imagePath;

//        MultipartFile file = null;
       //默认不指定key的情况下,以文件内容的hash值作为文件名
       String key = userName;
       Auth auth = Auth.create(accessKey, secretKey);
       String upToken = auth.uploadToken(bucket);
       try {
Response response = uploadManager.put(file.getInputStream(), key, upToken,null,null);
           //解析上传成功的结果
           DefaultPutRet putRet = new Gson().fromJson(response.bodyString(), DefaultPutRet.class);
           System.out.println(putRet.key);
           System.out.println(putRet.hash);
       } catch (
QiniuException ex)
{
Response r = ex.response;
           System.err.println(r.toString());
           try {
System.err.println(r.bodyString());
           } catch (QiniuException ex2) {
}
} catch (IOException e) {
e.printStackTrace();
       }
return "";
   }
}

图片上传接口

   public String upUserImage(HttpServletRequest httpServletRequest,HttpServletResponse httpServletResponse,Model model, MultipartFile file) {
try {
String token = CookieUtile.getCookieValue(httpServletRequest, "token");
           String s1 = null;
           String s2 = null;
//                 if (token != null) {
           String mes = desUtil.decrypt(token);
           String[] array = mes.split(":");
//                     s1 = array[0];
           s2 = array[1];
           loggerController.info("账户" + s2);
//             UpImgResult result = new UpImgResult();
//            User user = (User) request.getSession().getAttribute("currentUser");
           //默认不指定key的情况下,以文件内容的hash值作为文件名
           String key = s2;
           qiNiuImage.upImage(file, s2);


明天计划完成的事情:

完成图片上传接口.


遇到的困难:

前端页面

后端接口

前后端无法进行传值.加上@RequestParam(value = "file")这个并保持前后端数据一致也无法传值..


任务进度:任务7步骤2

任务开始时间:2017-11-13

预计demo时间:2017-11-21

是否有延期风险:暂无

禅道:http://task.ptteng.com/zentao/task-view-13475.html



返回列表 返回列表
评论

    分享到