希望有人可以帮助解决这个问题。
基本上,我们使用 ng-flow https://github.com/flowjs/ng-flow来允许拖放以上传项目。我们也在使用 MVC 4。
一切似乎都在正常工作,但是,我们希望对其进行自定义,以便
- 项目被拖入上传框并存储在范围内(就像现在一样)
- 在单击按钮之前不会实际上传项目
到目前为止,我们尝试了什么?:-
在配置中,我们禁用了目标,使其不会立即上传
.config(['flowFactoryProvider', function (flowFactoryProvider) {
flowFactoryProvider.defaults = {
target: '',
permanentErrors: [500, 501],
maxChunkRetries: 1,
chunkRetryInterval: 5000,
simultaneousUploads: 1
};
在实际页面上,我们创建了一个按钮,通过 ng-click 将通过 flow.files
<input type="button" value="Click Me" ng-click="uploadme($flow.files)">
在控制器中,我们有函数uploadme,它接受流作为参数。循环通过此参数并将每个“文件”发布到上传控制器
$scope.uploadme= function (flows)
{
angular.forEach(flows, function (flow) {
var fd = new FormData();
fd.append("file", flow);
$http.post("upload", fd, {
withCredentials: true,
headers: {'Content-Type': undefined },
transformRequest: angular.identity
})
});
}
MVC 控制器,“上传”。这个被调用,但是,文件总是空的
public ActionResult upload(HttpPostedFileBase file)
{
if (file.ContentLength > 0)
{
var fileName = Path.GetFileName(file.FileName);
var path = Path.Combine(Server.MapPath("~/App_Data/uploads"), fileName);
file.SaveAs(path);
}
return View();
}
有什么我们缺少的吗?或者有没有不同的方法来实现这一点。