Jersey RESTful WebService框架学习(七)文件上传
引入jar包:jersey-media-multipart-2.22.jar
前端:
<body>
<input id="commonFile" type="file" class="commonFile"
onchange='angular.element(this).scope().commonFileChanged(this)'
multiple="multiple" />
<br>
</body>
<script type="text/javascript">
angular.module("uploadApp", []).controller("uploadCtrl",
function($scope, $http) {
$scope.commonFileChanged = function() {
var $$fd = new FormData();
var _file = document.getElementById("commonFile");
$$fd.append('file', _file.files[0]);
$http({
method : 'post',
data : $$fd,
//拼装uri路径参数
url : "/Jersey/api/1.0/my/upload",
headers : {
'Content-Type' : undefined
},
/*序列化 formdata object*/
transformRequest : angular.identity
}).success(function(data) {
alert(angular.toJson(data));
});
};
});
angular.bootstrap(document, [ 'uploadApp' ]);
</script>
后端:
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Path("/upload")
@Produces({ MediaType.APPLICATION_JSON + ";charset=UTF-8" })
public String upload(@FormDataParam("file") InputStream fileInputStream,@FormDataParam("file") FormDataContentDisposition disposition) {
String nFileName = disposition.getFileName();
File file = new File("D:\\file\\" + nFileName);
try {
// 使用common io的文件写入操作
FileUtils.copyInputStreamToFile(fileInputStream, file);
} catch (IOException ex) {
ex.printStackTrace();
}
return "{\"success\",\"true\"}";
}
Jersey RESTful WebService框架学习(七)文件上传的更多相关文章
- Jersey RESTful WebService框架学习(一)
介绍:RESTful (Representation State Transfer) 描述了一个架构样式的网络系统,比如 web 应用程序.它首次出现在 2000 年 Roy Fielding 的博士 ...
- Jersey RESTful WebService框架学习(六)接收MultivaluedMap类型参数
现在的web开发中有些工程会觉得实体bean的架构会比较重,现在的持久层的框架的特点也层出不穷,核心思想的ORM在此基础上,提供了很多便捷操作,mybatis,jfinal(内部持久层框架)之类的也诞 ...
- Jersey RESTful WebService框架学习(八)maven搭建
一.pom文件: <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www. ...
- Jersey RESTful WebService框架学习(五)使用@BeanParam
第一步:定义一个实体类 注意:实体类的属性需要加上FormParam注解 public class User { @FormParam("name") private String ...
- Jersey RESTful WebService框架学习(八)文件下载防乱码
最近在做下载时候 不同浏览器下载的文件一直出现乱码,不知道怎么设置文件的编码,百度许久,找到一个解决办法如下 /** * 文件下载 * @param request * @return */ @GE ...
- Jersey RESTful WebService框架学习(四)使用@FormParam
前端 <form action="/Jersey/api/1.0/my/form" method="post"> <input type=&q ...
- Jersey RESTful WebService框架学习(三)使用@QueryParam
介绍:@QueryParamuri路径请求参数写在方法的参数中,获得请求路径附带的参数.比如:@QueryParam("desc") String desc 前端控制 <!D ...
- Jersey RESTful WebService框架学习(二)使用@PathParam
@PathParamuri路径参数写在方法的参数中,获得请求路径参数.比如:@PathParam("username") String userName 前端请求: <!DO ...
- Jersey框架一:Jersey RESTful WebService框架简介
Jersey系列文章: Jersey框架一:Jersey RESTful WebService框架简介 Jersey框架二:Jersey对JSON的支持 Jersey框架三:Jersey对HTTPS的 ...
随机推荐
- npoi设置数据有效性
npoi设置数据有效性 public void SetDataValidate(ISheet sheet, int firstCol, int lastCol) { CellRangeAddressL ...
- Ado.net简单快捷帮助类
using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; usin ...
- #define INVSQRT2 0.707106781 平方根倒数速算法
转自 http://www.cnblogs.com/pkuoliver/archive/2010/10/06/1844725.html 源码下载地址:http://diducoder.com/sotr ...
- "cni0" already has an IP address different from 10.244.2.1/24。 Error while adding to cni network: failed to allocate for range 0: no IP addresses available in range set: 10.244.2.1-10.244.2.254
"cni0" already has an IP address different from 10.244.2.1/24. Error while adding to cni n ...
- (转)在WCF服务的ServiceReferences.ClientConfig中使用相对路径
问题: Silverlight项目中添加服务引用后会在Silverlight项目中生成一个ServiceReferences.ClientConfig文件,这个文件中包含了引用服务的绑定(bindin ...
- appache压力测试
apache自带压力工具测试说明: Usage: ab [options] [http[s]://]hostname[:port]/pathOptions are: -n requests Numbe ...
- 没加载redis类,却可以实例化redis
原因:phpinfo里面已有redis扩展
- Spring 注解驱动(一)基本使用规则
Spring 注解驱动(一)基本使用规则 Spring 系列目录(https://www.cnblogs.com/binarylei/p/10198698.html) 一.基本使用 @Configur ...
- 爬虫初窥day2:正则
正则在线测试 http://tool.oschina.net/regex https://www.regexpal.com/ http://tool.chinaz.com/regex exp1:筛选所 ...
- 高负载PHP调优
高负载PHP调优 针对PHP的Linux调优 调整文件描述符限制 # ulimit -n 1000000 # vi /etc/security/limits.conf # Setting Shell ...