ng-file-uploadファイルアップロード


詳細
フロントエンド



    
        
    
    
    
    
    
        var app = angular.module('app', ['ngFileUpload']);
        app.controller('bmcuCtrl',
		[ '$scope', 'Upload', function($scope, Upload) {
			$scope.uploadFile = function() {
				  Upload.upload({
	                    //     
	                    url: 'api/customer/uploadBatchFile',
	                    //         
	                    data: {},
	                    file: $scope.file
	                }).progress(function (evt) {
	                    //   
	                    var progressPercentage = parseInt(100.0 *
                          evt.loaded / evt.total);          
                          console.log('progess:'+progressPercentage+ 
                          '%' + evt.config.file.name);
	                }).success(function (data, status, headers, config) {
	                    //    
	                    console.log('file ' + config.file.name 
                           + 'uploaded. Response: ' + data);
	                }).error(function (data, status, headers, config) {
	                    //    
	                    console.log('error status: ' + status);
	                });
			}
	} ]);
    


	


バックエンド:
@Controller
@RequestMapping("/api/customer")
@ResponseBody
public class TestNgUpload{

@RequestMapping("/uploadBatchFile'")
    public void uploadBatchFile'(HttpServletRequest request) throws Exception {
        CommonsMultipartResolver multipartResolver =
            new CommonsMultipartResolver(request.getSession().getServletContext());
        if(multipartResolver.isMultipart(request)){
            //  request       multipart     
            MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest) request;
            Iterator iter = multiRequest.getFileNames();
            while (iter.hasNext()) {
                String name = (String) iter.next();
                MultipartFile file = multiRequest.getFile(name);
                String fileName = file.getOriginalFilename();
                String format = fileName.substring(fileName.indexOf(".")+1);
                InputStream inputStream = file.getInputStream();
                Workbook wb = null;
                if (format.equals("xls") || format.equals("msexcel")) {
                    wb = new HSSFWorkbook(inputStream);
                }
                if (format.equals("xlsx")) {
                    wb = new XSSFWorkbook(inputStream);
                }
                String[][] objArray = ExcelUtil.readExcel(wb, 1);
                if(objArray.length>0){
                   BatchCustUnitVo batchCustUnitVo = new BatchCustUnitVo();
                   List accNbrList = new ArrayList();
                   List dataColList = new ArrayList();
                   for(int i=0;i} 
 
  • ExcelUtil.rar (1.7 KB)
  • : 0