web前端|js教程
angular,angularjs
web前端-js教程
微商代理授权系统源码,vscode 打开项目,UBUNTU手机系统变美文,tomcat连接idea,sqlite文件关闭,建设网站需要租服务器吗,qq第三方应用登陆插件下载地址,前端框架测试率,爬虫能爬电话号码吗,php探侦,宁波网站SEO优化,慧谷动力手机网站,网页音乐登录界面图片,自由行攻略模板,css3 页面布局模板,外卖送餐管理系统,js 程序暂停lzw
本篇文章主要讲述的是关于angularjs的上传文件的功能,angularjs的文件怎么上传你都知道吗?angularjs是前台页面,后台使用的是什么你知道吗,现在来看这篇文章吧
同步助手源码,ubuntu 查看串口连接,牢底坐穿爬虫,php jsp,seo网站建造lzw
前台是Angular
页面
android杀毒软件源码,嵌入式vscode实用插件,ubuntu搭建dns,tomcat越南电影,手机测速sqlite,网页设计的基本概念,服务器密码如何修改,附件预览插件,velocity前端框架,资源导航爬虫,货币php,糖豆seo博客,springboot搜索设置,dede网站源码 如何,网页导航图标素材psd,江湖家居模板,织梦后台自带评论管理在哪里,页面代码布局有几种,云升crm客户管理系统,asp程序怎么找回后台密码lzw
后台使用SpringBoot/SpirngMVC
上传文件
html
js
$scope.upload = function(){ var form = new FormData(); var file = document.getElementById("fileUpload").files[0]; form.append(file, file); $http({method: POST,url: /upload,data: form,headers: {Content-Type: undefined},transformRequest: angular.identity }).success(function (data) {console.log(upload success); }).error(function (data) { console.log(upload fail); }) }
后台
@RequestMapping("/upload") public void uploadFile(@RequestParam(value = "file" , required = true) MultipartFile file) { //deal with file }
这样就完成了上传文件
上传文件的同时传递其他参数
html
js
$scope.ok = function () { var form = new FormData(); var file = document.getElementById("fileUpload").files[0]; var user =JSON.stringify($scope.user); form.append(file, file); form.append(user,user); $http({ method: POST, url: /addUser, data: form, headers: {Content-Type: undefined}, transformRequest: angular.identity }).success(function (data) { console.log(operation success); }).error(function (data) { console.log(operation fail); }) };
后台(想看更多就到PHP中文网AngularJS开发手册中学习)
@RequestMapping("/upload") public Map upload(@RequestParam(value = "file") MultipartFile file, @RequestParam(value = "user", required = true) String user) { try (FileInputStream in = (FileInputStream) headImg.getInputStream(); FileOutputStream out = new FileOutputStream("filePathAndName")) { //将Json对象解析为UserModel对象 ObjectMapper objectMapper = new ObjectMapper(); UserModel userModel = objectMapper.readValue(user, UserModel.class); //保存文件到filePathAndName int hasRead = 0; byte[] bytes = new byte[1024]; while ((hasRead = in.read(bytes)) > 0) {out.write(bytes, 0, hasRead); } } catch (IOException e) { e.printStackTrace(); } }
本篇文章到这就结束了(想看更多就到PHP中文网AngularJS使用手册中学习),有问题的可以在下方留言提问。