使用 AngularJS 上传文件 [英] File Upload using AngularJS

查看:21
本文介绍了使用 AngularJS 上传文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的 HTML 表单:

Here is my HTML form:

<form name="myForm" ng-submit="">
    <input ng-model='file' type="file"/>
    <input type="submit" value='Submit'/>
</form>

我想从本地机器上传图片,并想读取上传文件的内容.所有这些我都想使用 AngularJS 来完成.

I want to upload an image from local machine and want to read the content of the uploaded file. All this I want to do using AngularJS.

当我尝试打印 $scope.file 的值时,它是未定义的.

When I try to print the value of $scope.file it comes as undefined.

推荐答案

这里的一些答案建议使用 FormData(),但不幸的是,该浏览器对象在 Internet Explorer 9 及更低版本中不可用.如果您需要支持那些较旧的浏览器,则需要一个备份策略,例如使用