cvjensen cvjensen - 1 year ago 102
Javascript Question

Populate ng-flow with jpeg/jpg as blob

I'm currently trying to populate ng-flow with images from my webserver(nodejs http-server), and I found this thread:

Populating image files with ng-flow.js from json

As you can see in the answer from Aidas, he says that you need to add the data to a blob and then use addFile(blob)

But... when I use $resource to GET an url like:


and then take the value from $resource, and adding it to a blob the image is missing - In ng-flow it says that the blob is 15kb - and not the 700kb the actually image is.

I've read that the picture could be base64 formatted, but my google dev console says:

content-type:image/jpeg; charset=utf-8

If I take a look at the response data in google dev console, there's alot of questionmarks (it cannot display the character I guess).

How do I get the response formatted correctly, so I can add it to ng-flow using the addFile(blob) function?

Answer Source

I ended up doing like this..

My $resource function look like:

ENV.imagesEndpoint = 'http://localhost:8080/

id = the image name / ID

getimages: $resource(ENV.imagesEndpoint + id, {}, {
    get: { 
      method: 'GET',  
      isArray: false,
      responseType: 'arraybuffer',
      transformResponse: function(data) {
        // Stores the ArrayBuffer object in a property called "data"
        return { data: data };
      //headers: {'Content-Type': 'image/jpeg;charset=utf-8;base64'}

My controller look like:

angular.forEach($scope.images, function(imageid) {
        filefactory(imageid).getimages.get().$promise.then(function(value) {
          $timeout(function() {
              var blob = new Blob([], {type: 'image/jpeg'});
     = 'file.jpg';