无法使用ng-file-upload逐个上传文件。流限制?

时间:2016-03-23 12:06:08

标签: javascript php angularjs

我使用了与此示例相同的代码:http://jsfiddle.net/danialfarid/2vq88rfs/136/

我遇到了以下问题。在浏览器方面,我可以在调试控制台中看到一切都很好:如果我发送了3个文件,我看到3个POST请求,状态为200.但是内部"上传"文件夹我只能找到一个(第一个)文件。

我发现服务器在保存上一个文件之前无法开始接收下一个文件。看起来像某种文件流限制。如何解决?

这是我的实际代码:

者:

this.uploadFiles = function(files) {
        $scope.files = files;
        angular.forEach(files, function(file) {
            file.upload = apiService.addFilesInDesk($rootScope.user.auth_token, $scope.deskData, file);

            file.upload.then(function (response) {
                $timeout(function () {
                    file.result = response.data;
                });
            }, function (response) {
                if (response.status > 0)
                    $scope.errorMsg = response.status + ': ' + response.data;
            }, function (evt) {
                file.progress = Math.min(100, parseInt(100.0 *
                    evt.loaded / evt.total));
            });
        });
    };

请求者:

addFilesInDesk: function (authToken, deskData, attachedFile) {
        var randParam = _getRandParam();
        var upload = Upload.upload({
            url: config.apiLink + 'UploadDeskFile',
            data: {
                uploadfile: attachedFile,  auth_token: authToken,
                rand_param: randParam, key: _getRequestKey(randParam), desk_id: 1
            }
        });

        return upload;
    }

服务器端:

public function actionUploadDeskFile()
{
    $return = array(
        'result' => 'failed',
        'error' => array()
    );
    $user = Users::model()->find('auth_token="' . $_POST['auth_token'] . '"');
    if ($user) {
        $ext = explode('.', $_FILES['uploadfile']['name']);
        $modelFiles = new Files();
        $modelFiles->user_id = $user->id;
        $modelFiles->name = $_FILES['uploadfile']['name'];
        $modelFiles->link = date('Y-m-d-H-i-s-u') . '_crmFile_' . $user->id . '.' . $ext[1];
        $modelFiles->type = 'CrmFile';
        $modelFiles->save();
        $modelDeskFiles = new CrmDeskFiles();
        $modelDeskFiles->client_desk_id = $_POST['desk_id'];
        $modelDeskFiles->file_id = $modelFiles->id;
        $modelDeskFiles->save();
        $uploadDir = $_SERVER['DOCUMENT_ROOT'] . '/uploads/';
        $uploadFile = $uploadDir . basename($_FILES['uploadfile']['name']);
        copy($_FILES['uploadfile']['tmp_name'], $uploadFile);
        copy($uploadFile, $uploadDir . date('Y-m-d-H-i-s-u') . '_crmFile_' . Yii::app()->user->id . '.' . $ext[1]);
        unlink($uploadFile);
    } else {
        $return['description'] = 'User does not exist';
    }
    Json::render($return);
}

0 个答案:

没有答案