5

希望有人可以帮助解决这个问题。

基本上,我们使用 ng-flow https://github.com/flowjs/ng-flow来允许拖放以上传项目。我们也在使用 MVC 4。

一切似乎都在正常工作,但是,我们希望对其进行自定义,以便

  1. 项目被拖入上传框并存储在范围内(就像现在一样)
  2. 在单击按钮之前不会实际上传项目

到目前为止,我们尝试了什么?:-

在配置中,我们禁用了目标,使其不会立即上传

.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();
    } 

有什么我们缺少的吗?或者有没有不同的方法来实现这一点。

4

2 回答 2

10

设法解决了这个问题......

从 div 标签中删除该行

flow-files-submitted="$flow.upload()"

然后单击按钮,将 $flow 作为参数传入

ng-click="InsertItems($flow)"

Javascript:-

$scope.InsertItems = function(e)
{
//Do what you need to do
e.upload();
}
于 2014-10-14T13:07:03.667 回答
2

我只想添加对这个问题的一个很好的答案的引用: Ng-flow upload programmatically

希望能帮助到你。

于 2015-07-15T14:44:56.007 回答