Angular.js ng-file-upload結合springMVC的使用教程
前言
本文主要給大家介紹了關于Angular.js文件上傳控件ng-file-upload結合springMVC使用的相關內(nèi)容,對于Angular.js文件上傳控件ng-file-upload不熟悉的朋友們可以先看看這篇文章(傳送門),下面話不多說,來看看詳細的使用介紹:
引入angular和ng-file-upload。
前端代碼
Upload.upload({
url: 'upload',
fields: {'username': 'zouroto'}, // additional data to send
file: file
}).progress(function (evt) {
var progressPercentage = parseInt(100.0 * evt.loaded / evt.total);
console.log('progress: ' + progressPercentage + '% ' + evt.config.file.name);
}).success(function (data, status, headers, config) {
console.log('file ' + config.file.name + 'uploaded. Response: ' + data);
});
springMVC代碼:
@Controller
public class UiController {
@ResponseStatus(HttpStatus.OK)
@RequestMapping(value = "/upload")
public void upload(@RequestParam("file") MultipartFile file, @RequestParam("username") String username ) throws IOException {
byte[] bytes;
if (!file.isEmpty()) {
bytes = file.getBytes();
//store file in storage
}
System.out.println(String.format("receive %s from %s", file.getOriginalFilename(), username));
}
}
application config
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> <property name="maxUploadSize" value="5000000"/> </bean>
maven
<dependency> <groupId>commons-fileupload</groupId> <artifactId>commons-fileupload</artifactId> <version>1.3.1</version> </dependency>
總結
以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學習或者工作能帶來一定的幫助,如果有疑問大家可以留言交流,謝謝大家對腳本之家的支持。
相關文章
ionic3+Angular4實現(xiàn)接口請求及本地json文件讀取示例
本篇文章主要介紹了ionic3+Angular4實現(xiàn)接口請求及本地json文件讀取示例,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-10-10
Angular實現(xiàn)類似博客評論的遞歸顯示及獲取回復評論的數(shù)據(jù)
這篇文章主要給大家介紹了關于Angular如何實現(xiàn)類似博客評論的遞歸顯示及獲取回復評論的數(shù)據(jù)的相關資料,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧。2017-11-11
AngularJS 實現(xiàn)JavaScript 動畫效果詳解
本文主要介紹AngularJS 實現(xiàn) JavaScript 動畫的資料,這里整理了詳細的資料和簡單示例代碼,有興趣的小伙伴可以參考下2016-09-09
詳解使用angular-cli發(fā)布i18n多國語言Angular應用
這篇文章主要介紹了詳解使用angular-cli發(fā)布i18n多國語言Angular應用,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-05-05

