flowjs / ng-flow

Flow.js html5 file upload extension on angular.js framework
http://flowjs.github.io/ng-flow/
MIT License
1.38k stars 303 forks source link

API question: how to force the submitted file? #271

Closed brazorf closed 8 years ago

brazorf commented 8 years ago

I am currently trying to integrate mrImage module with ng-flow in order to add image crop.

The external module will crop one image and save it to an angular model in base64 encoding. After the crop action i should tell ng-flow to upload that image source, but can't find how. Any suggestion?

brazorf commented 8 years ago

I'll provide more context.

Here's my markup:

<div flow-init="{testChunks: false}"
     flow-files-submitted="uploadError = false; upload($flow)"
     flow-file-success="success($message)"
     flow-file-error="error($message)"
     flow-name="uploader.flow">

And here's my controller:

controller: function($scope) {
    $scope.uploader = {};

    $scope.crop = function() {
        $scope.cropped = $scope.selector.crop();
        $scope.uploader.flow.addFile($scope.cropped);
    }
}

$scope.cropped contains the base64 encoded image. The error i get is as follows:

angular.js:11607 TypeError: Cannot read property 'replace' of undefined

I fear the flow instance i'm using is not the wrapper for the flow api.

brazorf commented 8 years ago

A step further, i think i've solved this for what matters ng-flow, this was probably more related to flowjs itself. However:

controller: function($scope) {
    $scope.uploader = {};

    $scope.crop = function() {
        $scope.cropped = $scope.selector.crop();
        var blob = new Blob([$scope.cropped], {type: "image/png"});
        blob.name = "test.png";
        $scope.uploader.flow.addFile(blob);
    }
}

This seems to work, even though i still have server side errors, probably related to flowjs or my server implementation itself.