【问题标题】:Angular file upload custom http post filesAngular文件上传自定义http post文件
【发布时间】:2017-05-24 01:26:07
【问题描述】:

我正在使用 nervgh/angular-file-upload 上传文件。据我所知,这个 angular-file-upload 有自己的上传功能。

目前我只需要uploader内的文件,然后我将使用我的自定义http post

$scope.UploadUserFiles = function () {
    $scope.UserFileRequest = {"File": uploader, "User": myUser}
    $http.post(host + "/api/user", $scope.UserFileRequest).then(function (response) { });
}

目前我无法从uploader 获取这些文件,因为我不知道属性和结构。但是User 是我自己在 web api 上的课程,所以我可以毫无问题地获取我想要的任何信息。

主要问题是我不知道如何在发布到我的 web api 后将 uploader 捕获/初始化为变量。

[HttpPost]
[Route("api/user")]
public UserFileResponse GetUserFile(UserFileRequest userFileRequest)
{
  //What should I do to get the Files from the request and save into the server?
}

我的UserFileRequest 包含myUser 的信息,但我不知道如何处理uploader,因为我没有上课。

【问题讨论】:

    标签: angularjs angular-file-upload


    【解决方案1】:

    根据我对您问题的理解,您无法将队列中的文件放入您自己的文件上传功能中。

    FileUploader 类中的函数具有您可以使用的回调,但另一种轻松公开文件队列的方法是在单击“上传”按钮后创建您自己的回调。

    someFxn(item) {
      console.log(item);
            
      _someUploadFxn(item)
    }
    <md-button class="md-blue" ng-click="$ctrl.someFxn(item)" ng-disabled="item.isReady || item.isUploading || item.isSuccess">
    Upload
    </md-button>

    这将允许您查看已排队的文件,然后您可以从那里将它或您需要的任何属性从该文件对象传递到您自己的上传器函数中。

    如果您想一次上传一堆文件,情况也是如此。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-28
      • 1970-01-01
      • 2011-02-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多