APP上传照片后台实现方法

APP上传照片,通过接口报错,代码如下:

// 接收三个图片、merId、merName、certId

		//创建一个通用的多部分解析器.
		CommonsMultipartResolver commonsMultipartResolver = new CommonsMultipartResolver(request.getSession().getServletContext());
		//设置编码
		commonsMultipartResolver.setDefaultEncoding("utf-8");
		//判断 request 是否有文件上传,即多部分请求...
		MultipartFile file1=null,file2=null,file3=null,file4=null,file5=null;
		if (commonsMultipartResolver.isMultipart(request))
		{
			//转换成多部分request
			MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest)request;
			file1 =  multipartRequest.getFile("file1");
			file2 =  multipartRequest.getFile("file2");
			file3 =  multipartRequest.getFile("file3");
			file4 =  multipartRequest.getFile("file4");
			file5 =  multipartRequest.getFile("file5");
		}
第二部分:

MultipartFile[] array = null;
array = new MultipartFile[]{ file1, file2, file3, file4, file5 };
generateAuditLogging(merId, certId, bankCardNo, openBank, merName,appId,tel, array,request);
第三部分:
for (int i = 0; i < array.length; i++) {
				String path = "E:\\photo\\" + merId + "_" + i + ".jpg";
				String fileName = merId + "_" + i + ".jpg";
				FileOutputStream fos = FileUtils.openOutputStream(new File(path));// 打开FileOutStrean流
				MultipartFile file = null;
				file = array[i];
				/*InputStream fis = new FileInputStream(file);*/
				InputStream fis = file.getInputStream();
				/*InputStream fis = (InputStream) file.getInputStream();*/
				String sizes = String.valueOf(fis.available() / 1024);
				System.out.println("sizes:" + sizes + "k"); // 文件大小
				IOUtils.copy(fis, fos);// 将MultipartFile
				// file转成二进制流并输入到FileOutStrean
				Date d = new Date();
				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
				String create_time = sdf.format(d);
				System.out.println("接受文件时间:" + create_time);
				pd.put("merId", merId);//商户号
				pd.put("name", merName);//姓名
				pd.put("sizes", sizes);
				pd.put("create_time", create_time);
				pd.put("fileName", fileName);
				pd.put("paths", path);
				paths.add(path);		
				fis.close();	
				fos.close();
				}
			}

就这样,代码有点乱,仔细看哦


你可能感兴趣的:(APP上传照片后台实现方法)