阅读背景:

图片上传流提交的一种方式 代码如下。

来源:互联网 

图片上传流提交的一种方式。


String urlFilePath = new String();
				urlFilePath = "图片路径";
				File direct = new File(filePath);
				DiskFileUpload dfu = new DiskFileUpload();
				dfu.setSizeMax(1024 * 1024 * 500);
				dfu.setSizeThreshold(1024 * 1024 * 5);
				dfu.setHeaderEncoding("UTF-8");
				dfu.setRepositoryPath(this.getServletContext().getRealPath("/"));
				List list = dfu.parseRequest(request);
				Iterator it = list.iterator();
				String lstr = Long.toString(System.currentTimeMillis());
				String fileName="";
				String imageUrl="";
				boolean flag=false;
				int i = 1;
				while (it.hasNext()) {
					try {
						FileItem item = (FileItem) it.next();
						if (!item.isFormField()) {
							fileName = lstr.substring(7)+i+item.getName().substring(item.getName().lastIndexOf("."));
							if (!direct.exists()) {
								direct.mkdirs();
							}
							InputStream choosestream = item.getInputStream();
							BufferedImage chooseimage = ImageUtils
									.getImage(choosestream);
							FileOutputStream fos = new FileOutputStream(filePath+ "/" + fileName);
							ImageIO.write(chooseimage, "jpg", fos);
							fos.close();
							choosestream.close();
							flag=true;
							i++;
						}else {
							if ("id".equals(item.getFieldName())) {
								new String(item.getString().getBytes("ISO-8859-1"), "UTF-8");
							}
						}
					} catch (Exception e) {
						System.err.println(e);
					}
String urlFilePath = new Str



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: