您好,登錄后才能下訂單哦!
前言
本文主要給大家介紹了關(guān)于Angular.js文件上傳控件ng-file-upload結(jié)合springMVC使用的相關(guān)內(nèi)容,對于Angular.js文件上傳控件ng-file-upload不熟悉的朋友們可以先看看這篇文章(傳送門),下面話不多說,來看看詳細(xì)的使用介紹:
引入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>
總結(jié)
以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作能帶來一定的幫助,如果有疑問大家可以留言交流,謝謝大家對億速云的支持。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。