2014-03-25 5 views
3

각도를 사용하고이 파일을 업로드하는 데이 plugin을 사용하고 있습니다. 기본적으로 파일 업로드에 대한 처리를 시작하지만 양식 제출을 시작하려고합니다. I는 제 함수 myFile = $scope.files; 같은 전역 변수를 만들려고각도 및 각도 파일 업로드로 파일 업로드

HTML

<form> 
    <input type="file" ng-file-select="onFileSelect($files)"> 
    <input type="submit" ng-click="sendMail()" value="send"> 
</form> 

JS

app.controller('mail', function ($scope, $http, $upload) { 

    $scope.onFileSelect = function($files) { 
     $scope.files = angular.copy($files); 
     console.log($scope.files); // Returns my object (size, type, name...) 
    } 

    $scope.sendMail = function() { 
    var file = myFile; 
    console.log(file);    // Still returns my object 
     $scope.upload = $upload.upload({ 
     url: 'server/mail.php', 
     data: { 
      // stuff 
     }, 
     file: file,    // Returns : Error: does not implement Blob 
     }).success(function(data, status, headers, config) { 
      console.log(data); 
     }); 
    } 

}) 

을 :

는 I이를 시도했다. 그런 다음 두 번째로 호출하십시오 : var file = myFile;. 콘솔 로그는 동일한 개체를 반환하지만 다음 오류가 발생합니다.

Error: Argument 2 of FormData.append does not implement interface Blob.

감사합니다.

답변

4

좋아요, 누군가 내게 답을 알려줍니다.

필자의 경우 angular.copy()는 변수 에서 개체으로 변경합니다. 그래서 나는 그것을 제거해야했습니다.

도울 수 있습니다.

1

여전히 angular.copy()를 사용하려는 경우이 문제를 해결할 수 있습니다. 나는 이것을 시도하고 이것이 효과가있다.

angular.copy()를 사용하는 대신 빈 배열 ('[]')로 배열을 연결하고 결과를 새 배열에 할당하십시오.

그래서, 아래 라인과 라인 $scope.files = angular.copy($files);을 대체 :

$scope.files = ($files || []).concat([]); 

이을() 메소드 사본의 마법을 수행해야합니다.

관련 문제