采用流的形式存储图片进行上传图片
来源:互联网 发布:抢票软件演唱会 编辑:程序博客网 时间:2024/05/18 19:45
// 上传图片
@RequestMapping("/upload")
public void upload(@RequestParam(value="file",required=false)MultipartFile file,HttpServletRequest request,ModelMap model, HttpServletResponse response,String id) throws IOException, SQLException{
Criteria ca = new Criteria("id", id);
log.info("开始上传机构图片");
Organization org = organizationService.getOrganization(ca);
org.setUpdatetime(new Date());
String newFileName =null;
String exe =null;
String path = request.getSession().getServletContext().getRealPath("/resources/images/upload");
Map<String, Object> map = new HashMap<String, Object>();
if(file.getOriginalFilename().length()==0){
MessageUtils.outputJSONResult("fail",response);
return;
}
else if(file!=null){
String fileName=file.getOriginalFilename();
exe = FilenameUtils.getExtension(fileName);
newFileName = UUID.randomUUID().toString();
File targetFile=new File(path+"\\"+newFileName+"."+exe);
if(!targetFile.exists()){
targetFile.mkdirs();
}
try {
file.transferTo(targetFile);
} catch (Exception e) {
e.printStackTrace();
log.error("上传失败");
}
log.info("上传路径和文件名"+request.getContextPath()+"/images/upload/"+fileName);
model.addAttribute("fileUrl", request.getContextPath()+"/images/upload/"+fileName+".jsp");
//request.getSession().setAttribute("fileName",request.getContextPath()+"/images/upload/"+newFileName+"."+exe);
map.put("fileUrl", request.getContextPath()+"/images/upload/"+newFileName+"."+exe);
}
String url = ConfigurationHelper.getDbUrl();
String userName = ConfigurationHelper.getUserName();
String password = ConfigurationHelper.getPassword();
Connection conn=null;
PreparedStatement statement = null;
try {
conn = DriverManager.getConnection(url, userName, password);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
log.error("数据库连接失败");
}
if(request.getParameter("s")!=null){
String sql="update organization set THUMBNAIL=? where id="+id;
statement = conn.prepareStatement(sql);
statement.setBlob(1, new FileInputStream(path+"\\"+newFileName+"."+exe));
model.addAttribute("log", "thumbnail");
}else{
String sql="update organization set PICTURE=? where id="+id;
statement = conn.prepareStatement(sql);
statement.setBlob(1, new FileInputStream(path+"\\"+newFileName+"."+exe));
model.addAttribute("log", "pic");
}
statement.executeUpdate();
statement.close();
//deleteFile(path);
MessageUtils.outputJSONResult("success",response);
//return "organization.upload";
}
0 0
- 采用流的形式存储图片进行上传图片
- 以二进制流的形式上传图片
- 采用IntentService进行多图片上传处理(包含相册的多图片的选择)
- 采用base64编码上传图片
- 图片上传与存储
- asp.net 图片上传的5种形式与说明
- 分享Magento后台Flash形式上传图片按钮的中文版
- js以字符串的形式将图片上传到服务器
- 七牛云存储之图片的上传【PHP】
- java存储H5上传的图片
- destoon 修改图片上传的存储路径
- 图片以二进制的形式存储到数据库并读取
- 以图片的形式存储单文档中的内容
- SQL SERVER 2008 进行图片的存储
- android上传图片到服务器(使用base64字节流的形式通过 AsyncHttpClient框架传输)
- android上传图片到服务器(使用base64字节流的形式通过 AsyncHttpClient框架传输)
- android上传图片到服务器(使用base64字节流的形式通过 AsyncHttpClient框架传输)
- android上传图片到服务器(使用base64字节流的形式通过 AsyncHttpClient框架
- ztree使用示例
- 关于本人三极管使用的一些经验
- Echarts3通过ajax动态获取数据,30秒定时图表数据,设置图表线条颜色和粗细
- setBackgroundResource造成的OOM和setBackground引发的思考
- Unity大型国战手游《六龙争霸》性能测评精讲
- 采用流的形式存储图片进行上传图片
- CSS基础案例展示
- 考研个人经验分享
- Linux windows 文件互传
- 处理上传图片的临时文件代码
- mysql 2013error
- StrutsRequestWrapper详解
- 2.tcpdump(1)
- String、StringBuffer与StringBuilder之间区别