简体   繁体   English

如何在AngularJS中上传多个文件

[英]How to Upload Multiple file in AngularJS

I use ngFileUpload for upload files but it can upload only 1 file. 我使用ngFileUpload上传文件,但它只能上传1个文件。

I want to upload and Image File and PDF File. 我想上传和图像文件和PDF文件。 How to upload multi file? 如何上传多个文件?

Help me please. 请帮帮我。

 (function () { 'use strict'; var app = angular.module('pageApp', ['ngFileUpload']); app.controller('MyCtrl', ['$scope', 'Upload', '$timeout', function ($scope, Upload, $timeout) { $scope.uploadPic = function (file) { file.upload = Upload.upload({ url: 'save_form.php', data: { file: file, username: $scope.username }, }); file.upload.then(function (response) { $timeout(function () { file.result = response.data; }); } }; }]); })(); 
  <form name="myForm"> Profile Picture: <input type="file" ngf-select="" ng-model="picFile" name="file" ngf-accept="'image/*'"> <br> Resume(.pdf): <input type="file" ngf-select="" ng-model="resumeFile" name="fileResume"> <br> <button ng-disabled="!myForm.$valid" ng-click="uploadPic(picFile)">Submit</button> </form> 

If you want to upload multiple files at the same time you can combine those 2 input field and add multiple attribute to the input tag. 如果要同时上载多个文件,可以组合这两个输入字段并将多个属性添加到输入标记。 Make sure your backend can accept multiple files / support the following features. 确保您的后端可以接受多个文件/支持以下功能。

<form name="myForm">    
      Picture & Resume: <input type="file" ngf-select="" 
               ng-model="picFile" name="file"  ngf-pattern="'image/*,application/pdf'" multiple>
      <br>

      <button ng-disabled="!myForm.$valid" ng-click="uploadPic(picFile)">Submit</button>
  </form>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM