java用httpclient 4.3 实现将base64串进行文件上传
2015-06-25 17:42
711 查看
在为app提供服务时,经常会遇到app传过来base64格式的文件,可通过将其转换为流的方式进行提交,代码如下:
CloseableHttpClient httpclient = HttpClients.createDefault(); try{ HttpPost post = new HttpPost(url); post.setEntity(MultipartEntityBuilder.create() .addPart("file", new InputStreamBody(new ByteArrayInputStream(new Base64Encoder().decode(base64Str)), "")) .addTextBody("source", SOURCE) .addTextBody("token", token) .addTextBody("exName", base64Str.substring(base64Str.indexOf("data:image/") + 11, base64Str.indexOf(";base64"))) .build()); HttpResponse response = httpclient.execute(post); HttpEntity entitys = response.getEntity(); if (entitys != null) { System.out.prinln(EntityUtils.toString(entitys)); } }catch(Exception e){ e.printStackTrace(); }finally { try { httpclient.close(); } catch (IOException e) { e.printStackTrace(); } }
相关文章推荐
- HTTP长连接
- TCP慢启动、拥塞避免、快速重传、快速回复
- android使用ImageView加载本地SdCard图片和加载网络图片
- 计算机网络总结(二)
- Http请求Demo
- 网络知识点总结(一)
- VMware下ubuntu系统一直莫名其妙地连接无线网络导致Hadoop集群无法正常启动的解决方法
- AFHTTPRequestOperationManager当一个网络请求加入菊花
- iPhone作为热点为PC提供网络
- 下载网络附件
- 怎样在Linux中查看apache是用那个httpd.conf
- http://yjck.iteye.com/blog/1609232
- httpd配置文件详解(下)
- Linux上基于网络自动化安装系统(CentOS6.5+DHCP+TFTP+PXE)
- GRE写作论证论据素材大全—网络的作用及机遇
- 配置远程服务器,使hyper-v能够连接网络
- Http协议
- 通过httpclient进行打包进行采集数据方法。
- Android之ListView异步加载网络图片(优化缓存机制)
- Tomcat8配置SSL/TSL,Android通过HTTPS进行访问