博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
layui 上传图片回显并点击放大实现
阅读量:4327 次
发布时间:2019-06-06

本文共 4335 字,大约阅读时间需要 14 分钟。

1、页面代码布局

2、点击放大设置

var renderImg = function () {            form.render();            layer.photos({                photos: '.theImg'                , anim: 5 //0-6的选择,指定弹出图片动画类型,默认随机(请注意,3.0之前的版本用shift参数)            });        }

3、上传成功之后,回显

//图片上传        upload.render({            elem: '#uploadImg'            , url: "commonCtrl/receiptUpload" //必填项            , method: ''  //可选项。HTTP类型,默认post            , accept: 'images'            , acceptMime: 'image/*'            , data: {flag: "rotationChart"} //可选项。额外的参数,如:{id: 123, abc: 'xxx'}            , before: function (obj) { //obj参数包含的信息,跟 choose回调完全一致,可参见上文。                //预读本地文件示例,不支持ie8            }            ,done: function(res){                //如果上传失败                if(!res.success){                    return layer.alert('上传失败');                }                //上传成功                var img = '';                $("#rotationChartDiv").html(img);                $("#url").val(res.data.url);                //点击放大           renderImg();            }            ,error: function(){                layer.msg("上传失败");            }        });

end:补上上传接口实现代码

controller层

@RequestMapping(value = "/receiptUpload", method = RequestMethod.POST)  @ResponseBody  public YJLResponseModel receiptUpload(@RequestParam("file") MultipartFile img, @RequestParam String flag) {    return UploadUtil.fileUploadServices(img, flag);  }

service层:

public static Map fileUploadServices(MultipartFile file,                                                      String flag) {        Map
result = new HashMap<>(); String name = file.getOriginalFilename(); String suffixName = ""; /* * MultipartFile转File */ File f = null; try { if (!name.contains(".")) { errorMsg = "文件不能为空!"; throw new Exception(getErrorMsg()); } else { suffixName = name.substring(name.indexOf(".")); f = File.createTempFile("tmp", null); //通过MultipartFile的transferTo(File dest)这个方法来转存文件到指定的路径。MultipartFile转存后,无法再操作,会报错 file.transferTo(f); //在JVM进程退出的时候删除文件,通常用在临时文件的删除. f.deleteOnExit(); /* * File转byte */ byte[] buffer = null; if (f != null) { FileInputStream fis = new FileInputStream(f); ByteArrayOutputStream bos = new ByteArrayOutputStream(); byte[] b = new byte[1024]; int n; while ((n = fis.read(b)) != -1) { bos.write(b, 0, n); } fis.close(); bos.close(); buffer = bos.toByteArray(); /* * byte上传到webService */ UploadService myServiceImplService = new UploadService(); UploadServiceSoap msis = myServiceImplService.getUploadServiceSoap(); //是否上传成功 Holder
hb = new Holder<>(); //上传成功后文件的路径 Holder
hs = new Holder<>(); msis.uploadFile(buffer, flag, suffixName, hb, hs); if (hb.value) { setSuccess(true); Map
map = new HashMap<>(); map.put("url", hs.value); result.put("data",map); } else { errorMsg = "上传失败!"; } } else { errorMsg = "文件不能为空!"; throw new Exception(getErrorMsg()); } } } catch (Exception e) { e.printStackTrace(); logger.error(e.getMessage()); } finally{ result.put("msg",errorMsg); } return result; }

 

转载于:https://www.cnblogs.com/yangyuke1994/p/10194195.html

你可能感兴趣的文章
ImageView的常用属性
查看>>
关于sso单点登录以及通过路径直接访问Servlet
查看>>
提高服务存活率-----定时唤醒,灰度进程
查看>>
服务器内访问laravel框架 404错误(宝塔)
查看>>
在Form_Load里面调用Focus无效
查看>>
HttpContext.GetOwinContext().Authentication 报错 解决办法
查看>>
三十七、将背景图分成多份
查看>>
SpringCloud服务提供者
查看>>
apache常用配置
查看>>
JS匿名执行函数
查看>>
关于InputStream类的available()方法
查看>>
六边形架构模式
查看>>
HAOI2007 理想的正方形 单调队列
查看>>
(原创)c#学习笔记04--流程控制04--循环03--for循环
查看>>
从控制台输入一个五位数,计算各个数位之和
查看>>
为Sublime Text 3设置优雅的字体
查看>>
Eclipse使用Jetty(转)
查看>>
vim命令收集(持续中)
查看>>
Zynq -- 启动过程
查看>>
206. Reverse Linked List(LeetCode)
查看>>