base64编码上传图片java后台接收实例
来源:互联网 发布:东南大学软件学院学费 编辑:程序博客网 时间:2024/05/18 03:42
思路
前台传以data:image/jpeg;base64,开头的base64编码的String字符串,后台接收字符串以后先进行base64解码 .decodeBuffer(),转换成二进制编码,然后使用字节输出流FileOutputStream()将文件保存到指定目录下。
报下面的错误
Error parsing HTTP request header
Note: further occurrences of HTTP header parsing errors will be logged at DEBUG level.
要修改tomcat下sever.xml,header的大小 <Connector URIEncoding="UTF-8" connectionTimeout="20000" port="8000" protocol="HTTP/1.1" redirectPort="8443" maxHttpHeaderSize="10485760"/>
将base64编码转成二进制
// 通过base64来转化图片 imageFile = imageFile.replaceAll("data:image/jpeg;base64,", ""); BASE64Decoder decoder = new BASE64Decoder(); // Base64解码 byte[] imageByte = null; try { imageByte = decoder.decodeBuffer(imageFile); for (int i = 0; i < imageByte.length; ++i) { if (imageByte[i] < 0) {// 调整异常数据 imageByte[i] += 256; } } } catch (Exception e) { e.printStackTrace(); }
将二进制转成file文件
// 生成文件名 String files = new SimpleDateFormat("yyyyMMddHHmmssSSS") .format(new Date()) + (new Random().nextInt(9000) % (9000 - 1000 + 1) + 1000) + ".png"; // 生成文件路径 String filename = Constant.UPLOAD_PATH + files; try { // 生成文件 File imageFile = new File(filename); imageFile.createNewFile(); if(!imageFile.exists()){ imageFile.createNewFile(); } OutputStream imageStream = new FileOutputStream(imageFile); imageStream.write(imageByte); imageStream.flush(); imageStream.close(); } catch (Exception e) { e.printStackTrace(); }
阅读全文
1 0
- base64编码上传图片java后台接收实例
- iOS 图片base64编码 上传
- 采用base64编码上传图片
- base64编码图片上传不了
- 上传base64编码图片到七牛云
- Ios上传图片 后台接收
- base64图片文件上传实例
- Java后台服务器接收IOS客户端上传的图片
- Java 后台实现上传图片的接收并保存
- js上传图片预览,php后台接收实例,已改写为多图上传预览
- jQuery使用Base64 生成图片预览和java后台不同的接收处理方式
- java中BASE64编码实例
- 微信小程序上传图片+java 后端接收实例
- 文件字节流用base64编码之后,后台接收问题
- Java Base64编码转成图片
- (java)Base64 图片编码&&解码
- 第二篇 上传图片和Base64编码
- 图片压缩,Base64编码后上传服务器
- Google Chrome获取AR API,Daydream支持
- 设计模式之-工厂模式
- Zookeeper-Watcher机制与异步调用原理
- 在KEIL RVMDK 下为单一C文件生成.LIB文件 .
- GreenPlum 外部表external table 实战
- base64编码上传图片java后台接收实例
- 【个人笔记重点,不作为参考】主题:angular-cli
- 使用fileupload组件实现文件上传
- get_transform is not allowed to be called from a MonoBehaviour constructor (or instance field initia
- anaconda安装后,spyder和anaconda启动不了
- ElasticSearch中,集群(Cluster),节点(Node),分片(Shard),Indices(索引),replicas(备份)之间的关系
- nginx log_module分析
- keepass+ keepasshttp实现自动填充密码和账号
- iOS xib制作开发购物数量加减的按钮