问题
Normal to upload file I do
<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?
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?
回答1:
I think you should looked at the directive which has been created already ng-file-upload
Features
- Supports upload progress, cancel/abort upload while in progress, File drag and drop (html5), Directory drag and drop (webkit), CORS, PUT(html5)/POST methods.
- Cross browser file upload (HTML5 and non-HTML5) with Flash polyfill FileAPI. Allows client side validation/modification before uploading the file
- Direct upload to db services CouchDB, imgur, etc... with file's content type using $upload.http(). This enables progress event for angular http POST/PUT requests.
- Seperate shim file, FileAPI files are loaded on demand for non-HTML5 code meaning no extra load/code if you just need HTML5 support.
- Lightweight using regular $http to upload (with shim for non-HTML5 browsers) so all angular $http features are available.
回答2:
https://github.com/nervgh/angular-file-upload/ seems to handle large uploads very gracefully
来源:https://stackoverflow.com/questions/29332169/upload-big-files-in-spa-angular-express