在SPA中上传大文件(角度+快速)

问题描述:

我可以正常上传文件

<form method='post' enctype='multipart/form-data'>      
    <p><input type='text', name='name'/></p>            
    <p><input type='file', name='image'/></p>      
    <p><input type='submit', value='Wyślij'/></p>    
</form> 

如果我要发送此表单而不重新加载页面怎么办?

What if I want send this form without page reload?

我可以使用"new FileReader()"并将base64绑定到$ scope,但是对于大文件,它不能很好地工作.

I can use "new FileReader()" and bind base64 to $scope but with big files it doesn't work well.

我可以上传表单而不重新加载表单吗?

Can I upload my form without page reload in similar way like above?

我认为您应该查看已经创建的指令

I think you should looked at the directive which has been created already ng-file-upload

功能

  1. 支持上传进度,进行中的取消/中止上传,文件拖放(html5),目录拖放(webkit),CORS,PUT(html5)/POST方法.
  2. 使用Flash polyfill FileAPI跨浏览器上传文件(HTML5和非HTML5).允许客户端在上传文件之前进行验证/修改
  3. 使用$ upload.http()将文件的内容类型直接上传到数据库服务CouchDB,imgur等.这将启用有角度的http POST/PUT请求的进度事件.
  4. 单独的shim文件,FileAPI文件按需加载非HTML5代码,这意味着如果您只需要HTML5支持,则无需额外的加载/代码.
  5. 使用常规的$ http进行轻量级上传(对于非HTML5浏览器使用shim进行上载),因此所有有角度的$ http功能均可用.