您的位置:首页 > 编程语言 > Java开发

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

2013-11-29 20:42 459 查看
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";
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: