|
1 | 1 | angularQFileUpload
|
2 | 2 | ==================
|
3 | 3 |
|
4 |
| -AngularJS qiniu cloud storage large file upload service with support resumble,progress |
| 4 | +AngularJS qiniu cloud storage large file upload service with support resumble,progress based on html5 file blob reader |
| 5 | + |
| 6 | +**Only woking under html5** |
| 7 | + |
| 8 | +## Install |
| 9 | + |
| 10 | +``` |
| 11 | +bower install angular-qiniu-upload |
| 12 | +``` |
| 13 | + |
| 14 | +## Usage |
| 15 | + |
| 16 | +- Add 'angularQFileUpload' to your main module's list of dependencies. |
| 17 | + |
| 18 | +``` |
| 19 | +<script> |
| 20 | + var myApp = angular.module('myApp', ['angularQFileUpload']); |
| 21 | +</script> |
| 22 | +``` |
| 23 | + |
| 24 | +- Upload file |
| 25 | + |
| 26 | +``` |
| 27 | + $scope.selectFiles = []; |
| 28 | +
|
| 29 | + var start = function (index) { |
| 30 | + $scope.selectFiles[index].progress = { |
| 31 | + p: 0 |
| 32 | + }; |
| 33 | + $scope.selectFiles[index].upload = $qupload.upload({ |
| 34 | + key: '<your qiniu file key>', |
| 35 | + file: $scope.selectFiles[index].file, |
| 36 | + token: '<your qiniu UpToken>' |
| 37 | + }); |
| 38 | + $scope.selectFiles[index].upload.then(function (response) { |
| 39 | + // upload success |
| 40 | + $log.info(response); |
| 41 | + }, function (response) { |
| 42 | + // upload failure |
| 43 | + $log.info(response); |
| 44 | + }, function (evt) { |
| 45 | + // progress |
| 46 | + $scope.selectFiles[index].progress.p = Math.floor(100 * evt.loaded / evt.totalSize); |
| 47 | + }); |
| 48 | + }; |
| 49 | +
|
| 50 | + $scope.abort = function (index) { |
| 51 | + $scope.selectFiles[index].upload.abort(); |
| 52 | + $scope.selectFiles.splice(index, 1); |
| 53 | + }; |
| 54 | +
|
| 55 | + $scope.onFileSelect = function ($files) { |
| 56 | + var offsetx = $scope.selectFiles.length; |
| 57 | + for (var i = 0; i < $files.length; i++) { |
| 58 | + $scope.selectFiles[i + offsetx] = { |
| 59 | + file: $files[i] |
| 60 | + }; |
| 61 | + start(i + offsetx); |
| 62 | + } |
| 63 | + }; |
| 64 | +``` |
| 65 | +-- reference, [http://developer.qiniu.com/docs/v6/api/reference/up/](http://developer.qiniu.com/docs/v6/api/reference/up/) |
0 commit comments