本文介绍了flow.js 点击上传文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

希望有人能帮助解决这个问题.

Hopefully someone can help with this.

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

Basically, we are using ng-flow https://github.com/flowjs/ng-flow to allow for drag and drop to upload items.We are also using MVC 4.

似乎一切正常,但是,我们想对其进行自定义,以便

All seems to be working as should, however, we would like to customize this, so that

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

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

What have we tried so far? :-

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

in the config, we have disabled the target so that it doesn't upload immediately

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

在实际页面上,我们创建了一个按钮,通过 ng-click 将通过 flow.files

on the actual page, we have created a button, with an ng-click which will pass through the flow.files

<input type="button" value="Click Me" ng-click="uploadme($flow.files)">

在控制器中,我们有函数uploadme,它接受流作为参数.循环遍历此参数并将每个文件"发布到上传控制器

in the controller, we have the function, uploadme, that accepts flows as a paramater.Looping through this paramater and post each "file" to the upload controller

$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 控制器,上传".这被调用,但是,文件始终为空

MVC controller, 'upload'. this get called, however, file is always null

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

有什么我们遗漏的吗?或者有没有不同的方法来实现这一点.

Is there something that we are missing? or is there a different way to achieve this.

推荐答案

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

managed to resolve this...

从 div 标签中删除该行

remove the line from div tag

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

然后点击一个按钮,将 $flow 作为参数传入

then onclick of a button, pass in $flow in as a paramater

ng-click="InsertItems($flow)"

Javascript:-

Javascript:-

$scope.InsertItems = function(e)
{
//Do what you need to do
e.upload();
}

这篇关于flow.js 点击上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 13:02