我正在尝试使用 FlowJS Angular 插件来实现上传功能,我需要对其进行一些调整。 我将需要所有类型的文件
我正在使用 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 Controller
[HttpPost]
public string UploadFile(HttpPostedFileBase file)
{
int fileSizeInBytes = file.ContentLength;
MemoryStream target = new MemoryStream();
file.InputStream.CopyTo(target);
byte[] data = target.ToArray();
return "";
}
这工作正常,但是当我上传多个文件时,每次都会点击一个文件的 Controller 。我需要找到一种方法将所有文件立即发送到 Controller ,例如
public string UploadFile(HttpPostedFileBase[] file)
{
}
有什么方法可以实现这个目标吗?
最佳答案
您的 Controller 中不需要类似 UploadFile(HttpPostedFileBase[] file)
的内容。
只需创建 Controller
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));
}
}
}
关于javascript - Flow Js - 将文件作为数组上传,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33797153/