簡體   English   中英

flow.js點擊上傳文件

[英]flow.js upload file on click

希望有人可以幫助解決這個問題。

基本上,我們使用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控制器,'上傳'。 但是,這個被調用,文件始終為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();
    } 

有什么東西我們缺少嗎? 或者有不同的方法來實現這一目標。

設法解決這個問題......

從div標簽中刪除該行

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

然后點擊一個按鈕,作為參數傳入$ flow

ng-click="InsertItems($flow)"

使用Javascript: -

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

我只想添加對這個問題的一個很好的答案的引用: Ng-flow上傳以編程方式

希望能幫助到你。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM