typescript 将文件转换为字节数组 Angular 2

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/45267800/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 04:45:00  来源:igfitidea点击:

Convert File to byte array Angular 2

angulartypescriptasp.net-web-api2

提问by C.Daniel

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?

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

采纳答案by JHS

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

你不会真正使用 Angular 来解决这个任务。JavaScript 具有处理文件数据的 API,例如 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:

PS:“Angular 2”现在被称为“Angular”,因为它们在版本 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.

正如您可能已经猜到的那样,一旦我们到达版本 4、5 等,术语“Angular 2”也被弃用了。也就是说,我们应该开始将它简单地命名为“Angular”,而没有版本后缀。

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

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(从更接近于“Angular 2”发布时)。