0

我正在尝试使用 FlowJS 角度插件来实现上传功能,我需要对其进行一些调整。我将不得不处理所有类型的文件

我正在使用 ASP.NET MVC。

.config(['flowFactoryProvider', function (flowFactoryProvider) {
flowFactoryProvider.defaults = {
 target: '',
 permanentErrors: [500, 501],
 maxChunkRetries: 1,
 chunkRetryInterval: 5000,
 simultaneousUploads: 1
};

我的输入按钮

<input type="file" flow-btn />

我的上传按钮

  <input type="button"  ng-click="uploadFiles($flow)">

和功能

 $scope.uploadme = function (flows) {
    flows.upload();
 });

我的 mvc 控制器

  [HttpPost]
    public string UploadFile(HttpPostedFileBase file)
    {
        int fileSizeInBytes = file.ContentLength;
        MemoryStream target = new MemoryStream();
        file.InputStream.CopyTo(target);
        byte[] data = target.ToArray();
        return "";
    }

这很好用,但是当我上传多个文件时,每次都会为一个文件点击控制器。我需要找到一种方法将所有文件一次发送到控制器,比如

    public string UploadFile(HttpPostedFileBase[] file)
    {
    }

我有什么办法可以做到这一点?

4

2 回答 2

1

您不需要UploadFile(HttpPostedFileBase[] file)控制器中的类似内容。

只需创建控制器

public string UploadFile()
{
  var httpRequest = HttpContext.Current.Request;
  //httpRequest.Files.Count -number of files
  foreach (string file in httpRequest.Files)
  {
      var postedFile = httpRequest.Files[file];
      using (var binaryReader = new BinaryReader(postedFile.InputStream))
      {
         //Your file
         string req = System.Text.Encoding.UTF8.GetString(binaryReader.ReadBytes(postedFile.ContentLength));

      }
}
}
于 2015-11-19T07:48:55.380 回答
1

multiple属性添加到您的input

<input type="file" multiple="multiple" flow-btn />
于 2015-11-19T07:52:20.670 回答