Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm using angular and this plugin to upload files. It basically starts processing on file upload but I'm tying to start on form submission.

I tried this :

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 tried to make a global variable like myFile = $scope.files; in the first function. Then calling it in the second like so : var file = myFile;. Console log returns the same object but I get the following error :

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

Thanks for any tip.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

Okay, so someone give me the answer.

In my case, angular.copy() changes the variable from File to Object. So I simply had to remove it.

Hop it can help.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.