加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

使用AngularJS进行文件上传

发布时间:2020-12-17 09:30:03 所属栏目:安全 来源:网络整理
导读:这是我的HTML表单: form name="myForm" ng-submit="" input ng-model='file' type="file"/ input type="submit" value='Submit'//form 我想从本地计算机上传图像,并想要读取上传文件的内容。所有这一切,我想使用AngularJS。 当我尝试打印$ scope.file的值
这是我的HTML表单:
<form name="myForm" ng-submit="">
    <input ng-model='file' type="file"/>
    <input type="submit" value='Submit'/>
</form>

我想从本地计算机上传图像,并想要读取上传文件的内容。所有这一切,我想使用AngularJS。

当我尝试打印$ scope.file的值它来自未定义。

这里的一些答案建议使用FormData(),但不幸的是,这是一个浏览器对象不可用Internet Explorer 9及以下。如果您需要支持这些旧版的浏览器,则需要使用备份策略,例如使用或Flash。

已经有很多Angular.js模块来执行文件上传。这两个显式支持旧版的浏览器:

> https://github.com/leon/angular-upload – 使用iframe作为后备广告
> https://github.com/danialfarid/ng-file-upload – 使用FileAPI / Flash作为后备

和一些其他选项:

> https://github.com/nervgh/angular-file-upload/
> https://github.com/uor/angular-file
> https://github.com/twilson63/ngUpload
> https://github.com/uploadcare/angular-uploadcare

其中一个应该适合你的项目,或者可以给你一些洞察如何自己编码。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读