2015-11-19 34 views
0

我想使用FlowJS角插件的上傳功能,我需要調整它一點。 我將不得不所有類型的文件流Js - 上傳文件作爲數組

我正在使用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) 
    { 
    } 

我能做到這一點的任何方式?

+0

哪裏是從那裏你選擇要上傳的文件'輸入型file'? – Mairaj

+0

@MairajAhmad我編輯了我的問題並添加了選擇文件按鈕。 –

+0

您是否嘗試過在'Request.Files'集合中查看哪些數據和多少個文件? – Andrew

回答

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)); 

     } 
} 
} 
+0

這種方法很好..但有沒有辦法做到這一點,沒有formdata?除了同一個保存操作中的文件之外,我還需要發送一些其他信息。我該如何實現它。 –

+0

如果我的回答對您有幫助,請立即投訴或接受。而且我看到你創建了一個類似問題的新問題,所以我認爲現在評論部分中的討論是不合適的。 –

+0

http://stackoverflow.com/questions/33864860/angularjs-ajax-mvc-file-multiple-upload-without-form-data。你對我的問題有任何意見嗎? –

0

添加multiple屬性您input

<input type="file" multiple="multiple" flow-btn /> 
+0

請添加更多信息來解釋如何解決這個問題 –