`
tanglong8848
  • 浏览: 67393 次
  • 性别: Icon_minigender_1
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

Java接收Flash请求的二进制流图片

 
阅读更多
	public HttpServletRequest request = ServletActionContext.getRequest();
	/**
	 * @Methed接收请求的二进制图片生成新的图片
	 * @disc get binary, create pic 
	 * @return 
	 */
	
	public void uploadImages(){
		
		try {
			InputStream  imgStream = request.getInputStream();
			if(imgStream!=null){
			String time=datefileFormat.format(new Date());
			String	imgfilename = time+ ".jpg";
				String path = ServletActionContext.getServletContext().getRealPath("/userfiles") + File.separator + imgfilename;
				File imageFile = new File(path); 
				if(!imageFile.exists()){
					imageFile.createNewFile();
				}
				FileOutputStream fos = new FileOutputStream(imageFile); 
				byte[] Buffer = new byte[1024*1024];
				int size = 0;
				while((size = imgStream.read(Buffer))!=-1){
				fos.write(Buffer,0,size);
				}	
                String getPath="userfiles/"+imgfilename;
				fos.close();
				imgStream.close();
				
				message="{\"success\":\"true\",\"path\":\""+getPath+"\"}";
				
			}

		} catch (Exception e) {
			message="{\"success\":\"false\",\"error\":\"01:系统错误\"}";
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		this.renderJson(message);
	}

遇到的问题,FLASH没有发出来二进制码, 加上以下代码成功。

FLASH没有加urlRequest.contentType = "application/octet-stream";

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics