将文件转换为字节数组Angular 2 [英] Convert File to byte array Angular 2

查看:160
本文介绍了将文件转换为字节数组Angular 2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用Angular2将输入文件(例如图像)转换为字节数组? 也许有人可以说什么更好:将图像转换为字节数组并将其发送到Web API或将文件对象"发送到API并在那里进行转换?

解决方案

您不会真正使用Angular解决此任务. JavaScript具有用于处理文件数据的API,例如 https://developer.mozilla.org/zh-CN/docs/Web/API/FileReader/readAsArrayBuffer

看到此问题

PS:"Angular 2"现在简称为"Angular",因为它们的版本为4:

您可能已经猜到,一旦到达第4、5等版本,"Angular 2"一词也会被弃用.也就是说,我们应该开始简单地将其命名为"Angular",而不要使用版本后缀.

http://angularjs.blogspot.com/2016/12/ok-let-me-explain-its-going-to-be.html

除非您是说您使用的是Angular的较早版本(从"Angular 2"发布之日起).

How can I convert input file(image,for example) to byte array by using Angular2 ? Maybe someone can say what is better: convert image to byte array and send it to Web API or send the File "object" to API and there convert it?

解决方案

You wouldn't really use Angular for solving this task. JavaScript has APIs for handling File data, e.g. https://developer.mozilla.org/en-US/docs/Web/API/FileReader/readAsArrayBuffer

See this question

PS: "Angular 2" is just called "Angular" now, because they're on version 4:

As you might have already guessed, the term "Angular 2" is also kind of deprecated once we get to version 4, 5 etc. That said, we should start naming it simply "Angular" without the version suffix.

http://angularjs.blogspot.com/2016/12/ok-let-me-explain-its-going-to-be.html

Unless you mean you are using an older version of Angular (from closer to when "Angular 2" released).

这篇关于将文件转换为字节数组Angular 2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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