填充NG-流与JPEG / JPG格式为BLOB [英] Populate ng-flow with jpeg/jpg as blob

查看:495
本文介绍了填充NG-流与JPEG / JPG格式为BLOB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在试图从我的网络服务器(HTTP的NodeJS服务器)填充NG流与图像,我发现这个线程:

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

<一个href=\"http://stackoverflow.com/questions/24007735/populating-image-files-with-ng-flow-js-from-json\">Populating与NG-flow.js图像文件从JSON

你可以从回声报答案看,他说,你需要将数据添加到一个blob,然后用addFile(BLOB)

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:

的http://本地主机:8080 / 3c6397ff-cbb4-4a1c-98b3- 5304e02c1bd4.jpg

然后采取从$资源的价值,并将其添加到一个blob图像丢失 - 在NG-FLOW它说,BLOB是15KB - 而不是700KB实际图像

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.

我读过的图片可以使用base64格式化,但是我的谷歌开发者控制台说:

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

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

如果我看一看在谷歌开发者控制台响应数据,还有很多questionmarks的(它不能显示我猜的字符)。

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).

我如何得到响应格式正确,这样我就可以添加使用addFile(BLOB)函数NG-流量?

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

推荐答案

最后我做这样的..

我的$资源功能如下:

ENV.imagesEndpoint ='的http://本地主机:8080 /

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

ID =图片名称/ ID

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([value.data], {type: 'image/jpeg'});
              blob.name = 'file.jpg';
              $scope.obj.flow.addFile(blob);
          });
        });
      });

这篇关于填充NG-流与JPEG / JPG格式为BLOB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆