码迷,mamicode.com
首页 > Web开发 > 详细

阿里云上传图片

时间:2016-12-27 18:09:15      阅读:237      评论:0      收藏:0      [点我收藏+]

标签:map   阿里   stack   path   addtab   date()   apk   alert   return   

//应用于EasyUI框架 js://图片上传 loadPic:function(index){ $(‘#hrAddTabs‘).datagrid(‘selectRow‘,index); var row = $("#hrAddTabs").datagrid("getSelected"); var code = $("#xlUserCode1").val(); $.ajaxFileUpload({ url:"data/uploadPics?xlUserCode="+code, secureuri:false, dataType:"json", fileElementId:[‘filePhoto‘,‘fileCard‘], success:function(msg){ if(msg!=false){ alert("上传成功"); $(‘#perPicMessage‘).window(‘close‘); }else{ alert("上传失败"); } }, error : function() { alert("上传失败"); $(‘#perPicMessage‘).window(‘close‘); } }); }, //控制器 @RequestMapping(value = "/uploadPics") @ResponseBody public boolean uploadApk( @RequestParam(value = "filePhoto") MultipartFile apkFile, HttpServletRequest request, HttpServletResponse response) throws FileNotFoundException { System.out.println("img"+(request.getSession().getServletContext().getRealPath("/"))); boolean flag = userDataServiceImpl.savaPic(apkFile, file, request); return flag; } //seveice /** * 阿里云上传图片 * @throws FileNotFoundException */ public boolean savaPic(MultipartFile apkFile, HttpServletRequest request) throws FileNotFoundException{ String xlCode = request.getParameter("xlUserCode");//获得用户编号 SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");//格式化时间 String date = sdf.format(new Date()); String fileName = apkFile.getOriginalFilename();// 原始文件名 String endName = fileName.substring(fileName.lastIndexOf(".")); String newFileName = date + endName;// 新文件名 OSSClient oss = new OSSClient("上传域名", "AccessKeyId", "AccessKeySecret"); InputStream inputStream1; try { inputStream1 =apkFile.getInputStream(); ObjectMetadata metadata = new ObjectMetadata(); metadata.setContentLength(apkFile.getSize()); oss.putObject("Bucket",newFileName, inputStream1, metadata); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } String idcard ="http://mastershao.cn/guanlihoutai2.0/"+newFileName; //身份证头像保存路径 boolean i = this.savePicPath(xlCode, idcard, usercard); //保存至数据库 if(i== true){ return true; } else{ return false; } }

阿里云上传图片

标签:map   阿里   stack   path   addtab   date()   apk   alert   return   

原文地址:http://www.cnblogs.com/jing-xw/p/smallwin.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!