Updating Naming and Files to Work With Services
This commit is contained in:
@@ -1,24 +1,20 @@
|
|||||||
{
|
{
|
||||||
"project": {
|
"project": {
|
||||||
"name": "ng2-file-upload"
|
"name": "ng2-chunk-file-upload"
|
||||||
},
|
},
|
||||||
"apps": [
|
"apps": [
|
||||||
{
|
{
|
||||||
"root": "demo/src",
|
"root": "demo/src",
|
||||||
"outDir": "demo/dist",
|
"outDir": "demo/dist",
|
||||||
"assets": [
|
"assets": ["assets"],
|
||||||
"assets"
|
|
||||||
],
|
|
||||||
"index": "index.html",
|
"index": "index.html",
|
||||||
"main": "main.ts",
|
"main": "main.ts",
|
||||||
"test": "../../scripts/test.ts",
|
"test": "../../scripts/test.ts",
|
||||||
"tsconfig": "tsconfig.json",
|
"tsconfig": "tsconfig.json",
|
||||||
"prefix": "",
|
"prefix": "",
|
||||||
"mobile": false,
|
"mobile": false,
|
||||||
"styles": [
|
"styles": [],
|
||||||
],
|
"scripts": [],
|
||||||
"scripts": [
|
|
||||||
],
|
|
||||||
"environmentSource": "environments/environment.ts",
|
"environmentSource": "environments/environment.ts",
|
||||||
"environments": {
|
"environments": {
|
||||||
"dev": "environments/environment.ts",
|
"dev": "environments/environment.ts",
|
||||||
|
|||||||
68
CHANGELOG.md
68
CHANGELOG.md
@@ -1,108 +1,108 @@
|
|||||||
<a name="1.3.0"></a>
|
<a name="1.3.0"></a>
|
||||||
# [1.3.0](https://github.com/valor-software/ng2-file-upload/compare/v1.2.0...v1.3.0) (2017-11-25)
|
# [1.3.0](https://github.com/valor-software/ng2-chunk-file-upload/compare/v1.2.0...v1.3.0) (2017-11-25)
|
||||||
|
|
||||||
|
|
||||||
### Features
|
### Features
|
||||||
|
|
||||||
* **file-upload:** Add response and function to modify the request body ([#901](https://github.com/valor-software/ng2-file-upload/pull/901))
|
* **file-upload:** Add response and function to modify the request body ([#901](https://github.com/valor-software/ng2-chunk-file-upload/pull/901))
|
||||||
* **file-upload** add file type .zip ([#911](https://github.com/valor-software/ng2-file-upload/pull/911))
|
* **file-upload** add file type .zip ([#911](https://github.com/valor-software/ng2-chunk-file-upload/pull/911))
|
||||||
|
|
||||||
### Bug Fixes
|
### Bug Fixes
|
||||||
* **file-uploader** Update: setOptions ([#904](https://github.com/valor-software/ng2-file-upload/pull/904))
|
* **file-uploader** Update: setOptions ([#904](https://github.com/valor-software/ng2-chunk-file-upload/pull/904))
|
||||||
* **docs** Fix correct path for isHTML5 option ([#844](https://github.com/valor-software/ng2-file-upload/pull/844))
|
* **docs** Fix correct path for isHTML5 option ([#844](https://github.com/valor-software/ng2-chunk-file-upload/pull/844))
|
||||||
* **docs** Added onFileDrop() event to documentation ([#857](https://github.com/valor-software/ng2-file-upload/pull/857))
|
* **docs** Added onFileDrop() event to documentation ([#857](https://github.com/valor-software/ng2-chunk-file-upload/pull/857))
|
||||||
|
|
||||||
|
|
||||||
<a name="1.2.1"></a>
|
<a name="1.2.1"></a>
|
||||||
## [1.2.1](https://github.com/valor-software/ng2-file-upload/compare/v1.2.0...v1.2.1) (2017-04-10)
|
## [1.2.1](https://github.com/valor-software/ng2-chunk-file-upload/compare/v1.2.0...v1.2.1) (2017-04-10)
|
||||||
|
|
||||||
|
|
||||||
### Features
|
### Features
|
||||||
|
|
||||||
* **package:** relaxed peer dependencies to allow ng v4 ([#713](https://github.com/valor-software/ng2-file-upload/issues/713)) ([7704e0e](https://github.com/valor-software/ng2-file-upload/commit/7704e0e))
|
* **package:** relaxed peer dependencies to allow ng v4 ([#713](https://github.com/valor-software/ng2-chunk-file-upload/issues/713)) ([7704e0e](https://github.com/valor-software/ng2-chunk-file-upload/commit/7704e0e))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<a name="1.2.0"></a>
|
<a name="1.2.0"></a>
|
||||||
# [1.2.0](https://github.com/valor-software/ng2-file-upload/compare/v1.1.3-0...v1.2.0) (2017-01-17)
|
# [1.2.0](https://github.com/valor-software/ng2-chunk-file-upload/compare/v1.1.3-0...v1.2.0) (2017-01-17)
|
||||||
|
|
||||||
|
|
||||||
### Bug Fixes
|
### Bug Fixes
|
||||||
|
|
||||||
* **headers:** Add FileItem headers to XHR ([#553](https://github.com/valor-software/ng2-file-upload/issues/553)) ([e4a7099](https://github.com/valor-software/ng2-file-upload/commit/e4a7099)), closes [#552](https://github.com/valor-software/ng2-file-upload/issues/552)
|
* **headers:** Add FileItem headers to XHR ([#553](https://github.com/valor-software/ng2-chunk-file-upload/issues/553)) ([e4a7099](https://github.com/valor-software/ng2-chunk-file-upload/commit/e4a7099)), closes [#552](https://github.com/valor-software/ng2-chunk-file-upload/issues/552)
|
||||||
|
|
||||||
|
|
||||||
### Features
|
### Features
|
||||||
|
|
||||||
* **file-select:** Clear file select automatically ([#524](https://github.com/valor-software/ng2-file-upload/issues/524)) ([410efda](https://github.com/valor-software/ng2-file-upload/commit/410efda))
|
* **file-select:** Clear file select automatically ([#524](https://github.com/valor-software/ng2-chunk-file-upload/issues/524)) ([410efda](https://github.com/valor-software/ng2-chunk-file-upload/commit/410efda))
|
||||||
* **fileUpload:** added additionalParameter ([#565](https://github.com/valor-software/ng2-file-upload/issues/565)) ([397de09](https://github.com/valor-software/ng2-file-upload/commit/397de09))
|
* **fileUpload:** added additionalParameter ([#565](https://github.com/valor-software/ng2-chunk-file-upload/issues/565)) ([397de09](https://github.com/valor-software/ng2-chunk-file-upload/commit/397de09))
|
||||||
* **package:** upgrade to ng v2.3+ ([#574](https://github.com/valor-software/ng2-file-upload/issues/574)) ([3cc6a99](https://github.com/valor-software/ng2-file-upload/commit/3cc6a99))
|
* **package:** upgrade to ng v2.3+ ([#574](https://github.com/valor-software/ng2-chunk-file-upload/issues/574)) ([3cc6a99](https://github.com/valor-software/ng2-chunk-file-upload/commit/3cc6a99))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<a name="1.1.3-0"></a>
|
<a name="1.1.3-0"></a>
|
||||||
## [1.1.3-0](https://github.com/valor-software/ng2-file-upload/compare/v1.1.2...v1.1.3-0) (2016-10-19)
|
## [1.1.3-0](https://github.com/valor-software/ng2-chunk-file-upload/compare/v1.1.2...v1.1.3-0) (2016-10-19)
|
||||||
|
|
||||||
|
|
||||||
### Bug Fixes
|
### Bug Fixes
|
||||||
|
|
||||||
* **typing:** added authTokenHeader property to options and file upload class ([b55c852](https://github.com/valor-software/ng2-file-upload/commit/b55c852))
|
* **typing:** added authTokenHeader property to options and file upload class ([b55c852](https://github.com/valor-software/ng2-chunk-file-upload/commit/b55c852))
|
||||||
|
|
||||||
|
|
||||||
### Features
|
### Features
|
||||||
|
|
||||||
* **build:** added support for AoT and ng-cli ([f0b2879](https://github.com/valor-software/ng2-file-upload/commit/f0b2879)), closes [#436](https://github.com/valor-software/ng2-file-upload/issues/436)
|
* **build:** added support for AoT and ng-cli ([f0b2879](https://github.com/valor-software/ng2-chunk-file-upload/commit/f0b2879)), closes [#436](https://github.com/valor-software/ng2-chunk-file-upload/issues/436)
|
||||||
* **file-upload:** Add the possibility of set the token header ([#213](https://github.com/valor-software/ng2-file-upload/issues/213)) ([282295c](https://github.com/valor-software/ng2-file-upload/commit/282295c))
|
* **file-upload:** Add the possibility of set the token header ([#213](https://github.com/valor-software/ng2-chunk-file-upload/issues/213)) ([282295c](https://github.com/valor-software/ng2-chunk-file-upload/commit/282295c))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<a name="1.1.2"></a>
|
<a name="1.1.2"></a>
|
||||||
## [1.1.2](https://github.com/valor-software/ng2-file-upload/compare/v1.1.1...v1.1.2) (2016-10-17)
|
## [1.1.2](https://github.com/valor-software/ng2-chunk-file-upload/compare/v1.1.1...v1.1.2) (2016-10-17)
|
||||||
|
|
||||||
|
|
||||||
### Features
|
### Features
|
||||||
|
|
||||||
* **package:** allow of ng2 v2.0.* and v2.*.* ([87395e6](https://github.com/valor-software/ng2-file-upload/commit/87395e6))
|
* **package:** allow of ng2 v2.0.* and v2.*.* ([87395e6](https://github.com/valor-software/ng2-chunk-file-upload/commit/87395e6))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<a name="1.1.1"></a>
|
<a name="1.1.1"></a>
|
||||||
## [1.1.1](https://github.com/valor-software/ng2-file-upload/compare/v1.0.3...v1.1.1) (2016-10-17)
|
## [1.1.1](https://github.com/valor-software/ng2-chunk-file-upload/compare/v1.0.3...v1.1.1) (2016-10-17)
|
||||||
|
|
||||||
|
|
||||||
### Bug Fixes
|
### Bug Fixes
|
||||||
|
|
||||||
* **uploader:** Add the ability to upload files via PUT instead of POST ([#239](https://github.com/valor-software/ng2-file-upload/issues/239)) ([e068511](https://github.com/valor-software/ng2-file-upload/commit/e068511))
|
* **uploader:** Add the ability to upload files via PUT instead of POST ([#239](https://github.com/valor-software/ng2-chunk-file-upload/issues/239)) ([e068511](https://github.com/valor-software/ng2-chunk-file-upload/commit/e068511))
|
||||||
* **zone.js:** error in Safari, Added Typings ([#221](https://github.com/valor-software/ng2-file-upload/issues/221)) ([db77e89](https://github.com/valor-software/ng2-file-upload/commit/db77e89))
|
* **zone.js:** error in Safari, Added Typings ([#221](https://github.com/valor-software/ng2-chunk-file-upload/issues/221)) ([db77e89](https://github.com/valor-software/ng2-chunk-file-upload/commit/db77e89))
|
||||||
|
|
||||||
|
|
||||||
### Features
|
### Features
|
||||||
|
|
||||||
* **multipart:** Create disableMultipart option in FileUploader ([#224](https://github.com/valor-software/ng2-file-upload/issues/224)) ([22307d2](https://github.com/valor-software/ng2-file-upload/commit/22307d2))
|
* **multipart:** Create disableMultipart option in FileUploader ([#224](https://github.com/valor-software/ng2-chunk-file-upload/issues/224)) ([22307d2](https://github.com/valor-software/ng2-chunk-file-upload/commit/22307d2))
|
||||||
* **package:** angular ~2.0.1 stable release ([#425](https://github.com/valor-software/ng2-file-upload/issues/425)) ([3fec385](https://github.com/valor-software/ng2-file-upload/commit/3fec385))
|
* **package:** angular ~2.0.1 stable release ([#425](https://github.com/valor-software/ng2-chunk-file-upload/issues/425)) ([3fec385](https://github.com/valor-software/ng2-chunk-file-upload/commit/3fec385))
|
||||||
* **package:** updated to typescript 2 ([4fef496](https://github.com/valor-software/ng2-file-upload/commit/4fef496))
|
* **package:** updated to typescript 2 ([4fef496](https://github.com/valor-software/ng2-chunk-file-upload/commit/4fef496))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<a name="1.1.0"></a>
|
<a name="1.1.0"></a>
|
||||||
# [1.1.0](https://github.com/valor-software/ng2-file-upload/compare/v1.0.3...v1.1.0) (2016-09-21)
|
# [1.1.0](https://github.com/valor-software/ng2-chunk-file-upload/compare/v1.0.3...v1.1.0) (2016-09-21)
|
||||||
|
|
||||||
|
|
||||||
### Bug Fixes
|
### Bug Fixes
|
||||||
|
|
||||||
* **uploader:** Add the ability to upload files via PUT instead of POST ([#239](https://github.com/valor-software/ng2-file-upload/issues/239)) ([e068511](https://github.com/valor-software/ng2-file-upload/commit/e068511))
|
* **uploader:** Add the ability to upload files via PUT instead of POST ([#239](https://github.com/valor-software/ng2-chunk-file-upload/issues/239)) ([e068511](https://github.com/valor-software/ng2-chunk-file-upload/commit/e068511))
|
||||||
* **zone.js:** error in Safari, Added Typings ([#221](https://github.com/valor-software/ng2-file-upload/issues/221)) ([db77e89](https://github.com/valor-software/ng2-file-upload/commit/db77e89))
|
* **zone.js:** error in Safari, Added Typings ([#221](https://github.com/valor-software/ng2-chunk-file-upload/issues/221)) ([db77e89](https://github.com/valor-software/ng2-chunk-file-upload/commit/db77e89))
|
||||||
|
|
||||||
|
|
||||||
### Features
|
### Features
|
||||||
|
|
||||||
* **multipart:** Create disableMultipart option in FileUploader ([#224](https://github.com/valor-software/ng2-file-upload/issues/224)) ([22307d2](https://github.com/valor-software/ng2-file-upload/commit/22307d2))
|
* **multipart:** Create disableMultipart option in FileUploader ([#224](https://github.com/valor-software/ng2-chunk-file-upload/issues/224)) ([22307d2](https://github.com/valor-software/ng2-chunk-file-upload/commit/22307d2))
|
||||||
* **package:** updated to typescript 2 ([4fef496](https://github.com/valor-software/ng2-file-upload/commit/4fef496))
|
* **package:** updated to typescript 2 ([4fef496](https://github.com/valor-software/ng2-chunk-file-upload/commit/4fef496))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<a name="1.0.3"></a>
|
<a name="1.0.3"></a>
|
||||||
## [1.0.3](https://github.com/valor-software/ng2-file-upload/compare/v1.0.2...v1.0.3) (2016-05-12)
|
## [1.0.3](https://github.com/valor-software/ng2-chunk-file-upload/compare/v1.0.2...v1.0.3) (2016-05-12)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -112,17 +112,17 @@
|
|||||||
|
|
||||||
### Bug Fixes
|
### Bug Fixes
|
||||||
|
|
||||||
* **upload:** merge fix and get filters fix ([ef6091c](https://github.com/valor-software/ng2-file-upload/commit/ef6091c))
|
* **upload:** merge fix and get filters fix ([ef6091c](https://github.com/valor-software/ng2-chunk-file-upload/commit/ef6091c))
|
||||||
|
|
||||||
|
|
||||||
### Chores
|
### Chores
|
||||||
|
|
||||||
* **build:** ng2 style guide applied ([aee69d8](https://github.com/valor-software/ng2-file-upload/commit/aee69d8))
|
* **build:** ng2 style guide applied ([aee69d8](https://github.com/valor-software/ng2-chunk-file-upload/commit/aee69d8))
|
||||||
|
|
||||||
|
|
||||||
### Features
|
### Features
|
||||||
|
|
||||||
* **package:** upgrade to angular 2.0.0-rc.1 ([#176](https://github.com/valor-software/ng2-file-upload/issues/176)) ([13c5c35](https://github.com/valor-software/ng2-file-upload/commit/13c5c35)), closes [#180](https://github.com/valor-software/ng2-file-upload/issues/180)
|
* **package:** upgrade to angular 2.0.0-rc.1 ([#176](https://github.com/valor-software/ng2-chunk-file-upload/issues/176)) ([13c5c35](https://github.com/valor-software/ng2-chunk-file-upload/commit/13c5c35)), closes [#180](https://github.com/valor-software/ng2-chunk-file-upload/issues/180)
|
||||||
|
|
||||||
|
|
||||||
### BREAKING CHANGES
|
### BREAKING CHANGES
|
||||||
|
|||||||
42
README.md
42
README.md
@@ -1,31 +1,31 @@
|
|||||||
# ng2-file-upload [](http://badge.fury.io/js/ng2-file-upload) [](https://npmjs.org/ng2-file-upload)[](https://ngx-slack.herokuapp.com)
|
# ng2-chunk-file-upload [](http://badge.fury.io/js/ng2-chunk-file-upload) [](https://npmjs.org/ng2-chunk-file-upload)[](https://ngx-slack.herokuapp.com)
|
||||||
Easy to use Angular2 directives for files upload ([demo](http://valor-software.github.io/ng2-file-upload/))
|
Easy to use Angular2 directives for files upload ([demo](http://valor-software.github.io/ng2-chunk-file-upload/))
|
||||||
|
|
||||||
[](https://github.com/mgechev/angular2-style-guide)
|
[](https://github.com/mgechev/angular2-style-guide)
|
||||||
[](https://travis-ci.org/valor-software/ng2-file-upload)
|
[](https://travis-ci.org/valor-software/ng2-chunk-file-upload)
|
||||||
[](https://david-dm.org/valor-software/ng2-file-upload)
|
[](https://david-dm.org/valor-software/ng2-chunk-file-upload)
|
||||||
|
|
||||||
## Quick start
|
## Quick start
|
||||||
|
|
||||||
1. A recommended way to install ***ng2-file-upload*** is through [npm](https://www.npmjs.com/search?q=ng2-file-upload) package manager using the following command:
|
1. A recommended way to install ***ng2-chunk-file-upload*** is through [npm](https://www.npmjs.com/search?q=ng2-chunk-file-upload) package manager using the following command:
|
||||||
|
|
||||||
`npm i ng2-file-upload --save`
|
`npm i ng2-chunk-file-upload --save`
|
||||||
|
|
||||||
Alternatively, you can [download it in a ZIP file](https://github.com/valor-software/ng2-file-upload/archive/master.zip).
|
Alternatively, you can [download it in a ZIP file](https://github.com/valor-software/ng2-chunk-file-upload/archive/master.zip).
|
||||||
|
|
||||||
2. Currently `ng2-file-upload` contains two directives: `ng2-file-select` and `ng2-file-drop`. `ng2-file-select` is used for 'file-input' field of form and
|
2. Currently `ng2-chunk-file-upload` contains two directives: `ng2-file-select` and `ng2-file-drop`. `ng2-file-select` is used for 'file-input' field of form and
|
||||||
`ng2-file-drop` is used for area that will be used for dropping of file or files.
|
`ng2-file-drop` is used for area that will be used for dropping of file or files.
|
||||||
|
|
||||||
3. More information regarding using of ***ng2-file-upload*** is located in
|
3. More information regarding using of ***ng2-chunk-file-upload*** is located in
|
||||||
[demo](http://valor-software.github.io/ng2-file-upload/) and [demo sources](https://github.com/valor-software/ng2-file-upload/tree/master/demo).
|
[demo](http://valor-software.github.io/ng2-chunk-file-upload/) and [demo sources](https://github.com/valor-software/ng2-chunk-file-upload/tree/master/demo).
|
||||||
|
|
||||||
## Using ***ng2-file-upload*** in a project
|
## Using ***ng2-chunk-file-upload*** in a project
|
||||||
|
|
||||||
1. Install as shown in the above section.
|
1. Install as shown in the above section.
|
||||||
|
|
||||||
2. Import `FileUploadModule` into the module that declares the component using ***ng2-file-upload***:
|
2. Import `FileUploadModule` into the module that declares the component using ***ng2-chunk-file-upload***:
|
||||||
|
|
||||||
```import { FileUploadModule } from 'ng2-file-upload';```
|
```import { FileUploadModule } from 'ng2-chunk-file-upload';```
|
||||||
|
|
||||||
3. Add it to `[imports]` under `@NgModule`:
|
3. Add it to `[imports]` under `@NgModule`:
|
||||||
|
|
||||||
@@ -33,7 +33,7 @@ Easy to use Angular2 directives for files upload ([demo](http://valor-software.g
|
|||||||
|
|
||||||
4. Import `FileUploader` into the component:
|
4. Import `FileUploader` into the component:
|
||||||
|
|
||||||
```import { FileUploader } from 'ng2-file-upload';```
|
```import { FileUploader } from 'ng2-chunk-file-upload';```
|
||||||
|
|
||||||
5. Create a variable for the API url:
|
5. Create a variable for the API url:
|
||||||
|
|
||||||
@@ -47,7 +47,7 @@ Easy to use Angular2 directives for files upload ([demo](http://valor-software.g
|
|||||||
|
|
||||||
### Properties
|
### Properties
|
||||||
|
|
||||||
- `uploader` - (`FileUploader`) - uploader object. See using in [demo](https://github.com/valor-software/ng2-file-upload/blob/master/demo/components/file-upload/simple-demo.ts)
|
- `uploader` - (`FileUploader`) - uploader object. See using in [demo](https://github.com/valor-software/ng2-chunk-file-upload/blob/master/demo/components/file-upload/simple-demo.ts)
|
||||||
|
|
||||||
### Events
|
### Events
|
||||||
- `onFileSelected` - fires when files are selected and added to the uploader queue
|
- `onFileSelected` - fires when files are selected and added to the uploader queue
|
||||||
@@ -56,7 +56,7 @@ Easy to use Angular2 directives for files upload ([demo](http://valor-software.g
|
|||||||
|
|
||||||
### Properties
|
### Properties
|
||||||
|
|
||||||
- `uploader` - (`FileUploader`) - uploader object. See using in [demo](https://github.com/valor-software/ng2-file-upload/blob/master/demo/components/file-upload/simple-demo.ts)
|
- `uploader` - (`FileUploader`) - uploader object. See using in [demo](https://github.com/valor-software/ng2-chunk-file-upload/blob/master/demo/components/file-upload/simple-demo.ts)
|
||||||
|
|
||||||
Parameters supported by this object:
|
Parameters supported by this object:
|
||||||
|
|
||||||
@@ -76,15 +76,15 @@ Easy to use Angular2 directives for files upload ([demo](http://valor-software.g
|
|||||||
### Events
|
### Events
|
||||||
|
|
||||||
- `fileOver` - it fires during 'over' and 'out' events for Drop Area; returns `boolean`: `true` if file is over Drop Area, `false` in case of out.
|
- `fileOver` - it fires during 'over' and 'out' events for Drop Area; returns `boolean`: `true` if file is over Drop Area, `false` in case of out.
|
||||||
See using in [ts demo](https://github.com/valor-software/ng2-file-upload/blob/master/demo/components/file-upload/simple-demo.ts) and
|
See using in [ts demo](https://github.com/valor-software/ng2-chunk-file-upload/blob/master/demo/components/file-upload/simple-demo.ts) and
|
||||||
[html demo](https://github.com/valor-software/ng2-file-upload/blob/master/demo/components/file-upload/simple-demo.html)
|
[html demo](https://github.com/valor-software/ng2-chunk-file-upload/blob/master/demo/components/file-upload/simple-demo.html)
|
||||||
- `onFileDrop` - it fires after a file has been dropped on a Drop Area; you can pass in `$event` to get the list of files that were dropped. i.e. `(onFileDrop)="dropped($event)"`
|
- `onFileDrop` - it fires after a file has been dropped on a Drop Area; you can pass in `$event` to get the list of files that were dropped. i.e. `(onFileDrop)="dropped($event)"`
|
||||||
|
|
||||||
# Troubleshooting
|
# Troubleshooting
|
||||||
|
|
||||||
Please follow this guidelines when reporting bugs and feature requests:
|
Please follow this guidelines when reporting bugs and feature requests:
|
||||||
|
|
||||||
1. Use [GitHub Issues](https://github.com/valor-software/ng2-file-upload/issues) board to report bugs and feature requests (not our email address)
|
1. Use [GitHub Issues](https://github.com/valor-software/ng2-chunk-file-upload/issues) board to report bugs and feature requests (not our email address)
|
||||||
2. Please **always** write steps to reproduce the error. That way we can focus on fixing the bug, not scratching our heads trying to reproduce it.
|
2. Please **always** write steps to reproduce the error. That way we can focus on fixing the bug, not scratching our heads trying to reproduce it.
|
||||||
|
|
||||||
Thanks for understanding!
|
Thanks for understanding!
|
||||||
@@ -106,7 +106,7 @@ Thanks for understanding!
|
|||||||
### Code snippet on how to use the Chunk File Feature on your code
|
### Code snippet on how to use the Chunk File Feature on your code
|
||||||
```typescript
|
```typescript
|
||||||
...
|
...
|
||||||
import { FileUploader } from 'ng2-file-upload';
|
import { FileUploader } from 'ng2-chunk-file-upload';
|
||||||
...
|
...
|
||||||
export class SimpleDemoComponent {
|
export class SimpleDemoComponent {
|
||||||
...
|
...
|
||||||
@@ -152,4 +152,4 @@ Thanks for understanding!
|
|||||||
|
|
||||||
### License
|
### License
|
||||||
|
|
||||||
The MIT License (see the [LICENSE](https://github.com/valor-software/ng2-file-upload/blob/master/LICENSE) file for the full text)
|
The MIT License (see the [LICENSE](https://github.com/valor-software/ng2-chunk-file-upload/blob/master/LICENSE) file for the full text)
|
||||||
|
|||||||
@@ -7,12 +7,18 @@ let gettingStarted = require('html-loader!markdown-loader!../getting-started.md'
|
|||||||
template: `
|
template: `
|
||||||
<main class="bd-pageheader">
|
<main class="bd-pageheader">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<h1>ng2-file-upload</h1>
|
<h1>ng2-chunk-file-upload</h1>
|
||||||
<p>The Angular2 File Upload directives</p>
|
<p>The Angular2 File Upload directives</p>
|
||||||
<a class="btn btn-primary" href="https://github.com/valor-software/ng2-file-upload">View on GitHub</a>
|
<a class="btn btn-primary" href="https://github.com/valor-software/ng2-chunk-file-upload">View on GitHub</a>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-lg-1"><iframe src="https://ghbtns.com/github-btn.html?user=valor-software&repo=ng2-file-upload&type=star&count=true" frameborder="0" scrolling="0" width="170px" height="20px"></iframe></div>
|
<div class="col-lg-1">
|
||||||
<div class="col-lg-1"><iframe src="https://ghbtns.com/github-btn.html?user=valor-software&repo=ng2-file-upload&type=fork&count=true" frameborder="0" scrolling="0" width="170px" height="20px"></iframe></div>
|
<iframe src="https://ghbtns.com/github-btn.html?user=valor-software&repo=ng2-chunk-file-upload&type=star&count=true"
|
||||||
|
frameborder="0" scrolling="0" width="170px" height="20px"></iframe>
|
||||||
|
</div>
|
||||||
|
<div class="col-lg-1">
|
||||||
|
<iframe src="https://ghbtns.com/github-btn.html?user=valor-software&repo=ng2-chunk-file-upload&type=fork&count=true"
|
||||||
|
frameborder="0" scrolling="0" width="170px" height="20px"></iframe>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
@@ -25,7 +31,9 @@ let gettingStarted = require('html-loader!markdown-loader!../getting-started.md'
|
|||||||
|
|
||||||
<footer class="footer">
|
<footer class="footer">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<p class="text-muted text-center"><a href="https://github.com/valor-software/ng2-file-upload">ng2-file-upload</a> is maintained by <a href="https://github.com/valor-software">valor-software</a>.</p>
|
<p class="text-muted text-center">
|
||||||
|
<a href="https://github.com/valor-software/ng2-chunk-file-upload">ng2-chunk-file-upload</a>
|
||||||
|
is maintained by <a href="https://github.com/valor-software">valor-software</a>.</p>
|
||||||
</div>
|
</div>
|
||||||
</footer>
|
</footer>
|
||||||
`
|
`
|
||||||
|
|||||||
@@ -4,16 +4,21 @@ import { FormsModule } from '@angular/forms';
|
|||||||
import { BrowserModule } from '@angular/platform-browser';
|
import { BrowserModule } from '@angular/platform-browser';
|
||||||
|
|
||||||
import { TabsModule } from 'ngx-bootstrap/tabs';
|
import { TabsModule } from 'ngx-bootstrap/tabs';
|
||||||
import { FileUploadModule } from 'ng2-file-upload';
|
import { FileUploadModule } from 'ng2-chunk-file-upload';
|
||||||
|
|
||||||
import { AppComponent } from './app.component';
|
import { AppComponent } from './app.component';
|
||||||
import { FileUploadSectionComponent } from './components/file-upload-section';
|
import { FileUploadSectionComponent } from './components/file-upload-section';
|
||||||
import { SimpleDemoComponent } from './components/file-upload/simple-demo';
|
import { SimpleDemoComponent } from './components/file-upload/simple-demo';
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
imports: [BrowserModule, CommonModule, FileUploadModule, TabsModule.forRoot(), FormsModule],
|
imports: [
|
||||||
|
BrowserModule,
|
||||||
|
CommonModule,
|
||||||
|
FileUploadModule,
|
||||||
|
TabsModule.forRoot(),
|
||||||
|
FormsModule,
|
||||||
|
],
|
||||||
declarations: [AppComponent, FileUploadSectionComponent, SimpleDemoComponent],
|
declarations: [AppComponent, FileUploadSectionComponent, SimpleDemoComponent],
|
||||||
bootstrap: [AppComponent]
|
bootstrap: [AppComponent],
|
||||||
})
|
})
|
||||||
export class AppModule {
|
export class AppModule {}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,19 +1,19 @@
|
|||||||
import { Component } from '@angular/core';
|
import { Component } from "@angular/core";
|
||||||
|
|
||||||
let doc = require('html-loader!markdown-loader!../../doc.md');
|
let doc = require("html-loader!markdown-loader!../../doc.md");
|
||||||
|
|
||||||
let tabDesc: Array<any> = [
|
let tabDesc: Array<any> = [
|
||||||
{
|
{
|
||||||
heading: 'Simple',
|
heading: 'Simple',
|
||||||
ts: require('!!raw-loader?lang=typescript!./file-upload/simple-demo.ts'),
|
ts: require("!!raw-loader?lang=typescript!./file-upload/simple-demo.ts"),
|
||||||
html: require('!!raw-loader?lang=markup!./file-upload/simple-demo.html'),
|
html: require("!!raw-loader?lang=markup!./file-upload/simple-demo.html"),
|
||||||
js: require('!!raw-loader?lang=javascript!./file-upload/file-catcher.js')
|
js: require("!!raw-loader?lang=javascript!./file-upload/file-catcher.js")
|
||||||
}
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'file-upload-section',
|
selector: "file-upload-section",
|
||||||
templateUrl: './file-upload-section.html'
|
templateUrl: "./file-upload-section.html",
|
||||||
})
|
})
|
||||||
export class FileUploadSectionComponent {
|
export class FileUploadSectionComponent {
|
||||||
public name: string = 'File Upload';
|
public name: string = 'File Upload';
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
import { FileUploader } from 'ng2-file-upload';
|
import { FileUploader } from 'ng2-chunk-file-upload';
|
||||||
|
|
||||||
// const URL = '/api/';
|
// const URL = '/api/';
|
||||||
const URL = 'https://evening-anchorage-3159.herokuapp.com/api/';
|
const URL = 'https://evening-anchorage-3159.herokuapp.com/api/';
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
### Usage
|
### Usage
|
||||||
```typescript
|
```typescript
|
||||||
import { FileSelectDirective, FileDropDirective, FileUploader } from 'ng2-file-upload/ng2-file-upload';
|
import { FileSelectDirective, FileDropDirective, FileUploader } from 'ng2-chunk-file-upload/ng2-chunk-file-upload';
|
||||||
```
|
```
|
||||||
|
|
||||||
### Annotations
|
### Annotations
|
||||||
@@ -18,7 +18,7 @@ import { FileSelectDirective, FileDropDirective, FileUploader } from 'ng2-file-u
|
|||||||
|
|
||||||
### Properties
|
### Properties
|
||||||
|
|
||||||
- `uploader` - (`FileUploader`) - uploader object. See using in [demo](https://github.com/valor-software/ng2-file-upload/blob/master/demo/components/file-upload/simple-demo.ts)
|
- `uploader` - (`FileUploader`) - uploader object. See using in [demo](https://github.com/valor-software/ng2-chunk-file-upload/blob/master/demo/components/file-upload/simple-demo.ts)
|
||||||
|
|
||||||
Parameters supported by this object:
|
Parameters supported by this object:
|
||||||
|
|
||||||
@@ -37,11 +37,11 @@ import { FileSelectDirective, FileDropDirective, FileUploader } from 'ng2-file-u
|
|||||||
|
|
||||||
### Properties
|
### Properties
|
||||||
|
|
||||||
- `uploader` - (`FileUploader`) - uploader object. See using in [demo](https://github.com/valor-software/ng2-file-upload/blob/master/demo/components/file-upload/simple-demo.ts)
|
- `uploader` - (`FileUploader`) - uploader object. See using in [demo](https://github.com/valor-software/ng2-chunk-file-upload/blob/master/demo/components/file-upload/simple-demo.ts)
|
||||||
|
|
||||||
### Events
|
### Events
|
||||||
|
|
||||||
- `fileOver` - it fires during 'over' and 'out' events for Drop Area; returns `boolean`: `true` if file is over Drop Area, `false` in case of out.
|
- `fileOver` - it fires during 'over' and 'out' events for Drop Area; returns `boolean`: `true` if file is over Drop Area, `false` in case of out.
|
||||||
See using in [ts demo](https://github.com/valor-software/ng2-file-upload/blob/master/demo/components/file-upload/simple-demo.ts) and
|
See using in [ts demo](https://github.com/valor-software/ng2-chunk-file-upload/blob/master/demo/components/file-upload/simple-demo.ts) and
|
||||||
[html demo](https://github.com/valor-software/ng2-file-upload/blob/master/demo/components/file-upload/simple-demo.html)
|
[html demo](https://github.com/valor-software/ng2-chunk-file-upload/blob/master/demo/components/file-upload/simple-demo.html)
|
||||||
- `onFileDrop` - it fires after a file has been dropped on a Drop Area; you can pass in `$event` to get the list of files that were dropped. i.e. `(onFileDrop)="dropped($event)"`
|
- `onFileDrop` - it fires after a file has been dropped on a Drop Area; you can pass in `$event` to get the list of files that were dropped. i.e. `(onFileDrop)="dropped($event)"`
|
||||||
|
|||||||
@@ -6,5 +6,5 @@
|
|||||||
|
|
||||||
Install the components
|
Install the components
|
||||||
```
|
```
|
||||||
npm install ng2-file-upload --save
|
npm install ng2-chunk-file-upload --save
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
|
||||||
<link rel="icon" href="data:;base64,iVBORw0KGgo=">
|
<link rel="icon" href="data:;base64,iVBORw0KGgo=">
|
||||||
<link rel="author" href="https://github.com/valor-software/ng2-file-upload/graphs/contributors">
|
<link rel="author" href="https://github.com/valor-software/ng2-chunk-file-upload/graphs/contributors">
|
||||||
|
|
||||||
<!--link to bootstrap.css-->
|
<!--link to bootstrap.css-->
|
||||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
|
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
|
||||||
|
|||||||
16778
package-lock.json
generated
Normal file
16778
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
23
package.json
23
package.json
@@ -1,8 +1,8 @@
|
|||||||
{
|
{
|
||||||
"name": "ng2-file-upload-base",
|
"name": "ng2-chunk-file-upload-base",
|
||||||
"version": "1.3.0",
|
"version": "1.3.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"description": "Angular file upload directives",
|
"description": "Angular file upload directives with Chunk Upload",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"lite-server": "lite-server -c demo/bs-config.json",
|
"lite-server": "lite-server -c demo/bs-config.json",
|
||||||
"demo.serve": "run-s build link demo.build lite-server",
|
"demo.serve": "run-s build link demo.build lite-server",
|
||||||
@@ -22,7 +22,7 @@
|
|||||||
"test-coverage": "ng test -sr -cc",
|
"test-coverage": "ng test -sr -cc",
|
||||||
"version": "npm run flow.changelog && git add -A"
|
"version": "npm run flow.changelog && git add -A"
|
||||||
},
|
},
|
||||||
"main": "bundles/ng2-file-upload.umd.js",
|
"main": "bundles/ng2-chunk-file-upload.umd.js",
|
||||||
"module": "index.js",
|
"module": "index.js",
|
||||||
"typings": "index.d.ts",
|
"typings": "index.d.ts",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
@@ -31,18 +31,20 @@
|
|||||||
"angularjs",
|
"angularjs",
|
||||||
"twitter-bootstrap",
|
"twitter-bootstrap",
|
||||||
"file-upload",
|
"file-upload",
|
||||||
"angular-file-upload"
|
"angular-file-upload",
|
||||||
|
"chunk-file-upload",
|
||||||
|
"azure-blob-storage"
|
||||||
],
|
],
|
||||||
"author": "Vyacheslav Chub <vyacheslav.chub@valor-software.com>",
|
"author": "Paulo Peres Jr <paulo@myog.io>",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git+ssh://git@github.com/valor-software/ng2-file-upload.git"
|
"url": "git+ssh://git@github.com/PauloPeres/ng2-chunk-file-upload.git"
|
||||||
},
|
},
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/valor-software/ng2-file-upload/issues"
|
"url": "https://github.com/PauloPeres/ng2-chunk-file-upload/issues"
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/valor-software/ng2-file-upload#readme",
|
"homepage": "https://github.com/PauloPeres/ng2-chunk-file-upload#readme",
|
||||||
"dependencies": {},
|
"dependencies": {},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@angular/common": "^2.3.1 || >=4.0.0",
|
"@angular/common": "^2.3.1 || >=4.0.0",
|
||||||
@@ -135,6 +137,11 @@
|
|||||||
"name": "Oleksandr Telnov",
|
"name": "Oleksandr Telnov",
|
||||||
"email": "otelnov@gmail.com",
|
"email": "otelnov@gmail.com",
|
||||||
"url": "https://github.com/otelnov"
|
"url": "https://github.com/otelnov"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Paulo Peres Jr",
|
||||||
|
"email": "paulo@myog.io",
|
||||||
|
"url": "https://github.com/PauloPeres/"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,11 +49,11 @@ export class FileChunk {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//getters and setters
|
//getters and setters
|
||||||
public setProgress(v: any) {
|
public setProgress(v: number) {
|
||||||
this.uploadProgress = v;
|
this.uploadProgress = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
public getProgress() {
|
public getProgress():number {
|
||||||
return this.uploadProgress;
|
return this.uploadProgress;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,11 +61,11 @@ export class FileChunk {
|
|||||||
this.uploading = v;
|
this.uploading = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
public getUploading() {
|
public getUploading():boolean {
|
||||||
return this.uploading;
|
return this.uploading;
|
||||||
}
|
}
|
||||||
|
|
||||||
public getUploadComplete() {
|
public getUploadComplete():boolean {
|
||||||
return this.uploadComplete;
|
return this.uploadComplete;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,11 +77,11 @@ export class FileChunk {
|
|||||||
this.uploadProgress = v;
|
this.uploadProgress = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
public getUploadProgress() {
|
public getUploadProgress():number {
|
||||||
return this.uploadProgress;
|
return this.uploadProgress;
|
||||||
}
|
}
|
||||||
|
|
||||||
public getStartByte() {
|
public getStartByte():number {
|
||||||
return this.startByte;
|
return this.startByte;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,7 +89,7 @@ export class FileChunk {
|
|||||||
this.startByte = v;
|
this.startByte = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
public getEndByte() {
|
public getEndByte():number {
|
||||||
return this.endByte;
|
return this.endByte;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,7 +97,7 @@ export class FileChunk {
|
|||||||
this.endByte = v;
|
this.endByte = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
public getByteStepSize() {
|
public getByteStepSize():number {
|
||||||
return this.byteStepSize;
|
return this.byteStepSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,11 +109,11 @@ export class FileChunk {
|
|||||||
this.totalSize = v;
|
this.totalSize = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
public getTotalSize() {
|
public getTotalSize():number {
|
||||||
return this.totalSize;
|
return this.totalSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
public getRawFile() {
|
public getRawFile():any {
|
||||||
return this.rawFile;
|
return this.rawFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,7 +121,7 @@ export class FileChunk {
|
|||||||
this.rawFile = v;
|
this.rawFile = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
public getCurrentChunk() {
|
public getCurrentChunk():number {
|
||||||
return this.currentChunk;
|
return this.currentChunk;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,7 +129,7 @@ export class FileChunk {
|
|||||||
this.currentChunk = v;
|
this.currentChunk = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
public getTotalChunks() {
|
public getTotalChunks():number {
|
||||||
return this.totalChunks;
|
return this.totalChunks;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,7 +141,7 @@ export class FileChunk {
|
|||||||
this.uniqueIdentifier = v;
|
this.uniqueIdentifier = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
public getUniqueIdenfier() {
|
public getUniqueIdenfier():string {
|
||||||
return this.uniqueIdentifier;
|
return this.uniqueIdentifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
|
import { HttpHeaders } from '@angular/common/http';
|
||||||
import { FileLikeObject } from './file-like-object.class';
|
import { FileLikeObject } from './file-like-object.class';
|
||||||
import { FileUploader, ParsedResponseHeaders, FileUploaderOptions } from './file-uploader.class';
|
import { FileUploader, FileUploaderOptions } from './file-uploader.class';
|
||||||
import { FileChunk } from './file-chunk.class'
|
import { FileChunk } from './file-chunk.class'
|
||||||
export class FileItem {
|
export class FileItem {
|
||||||
public file: FileLikeObject;
|
public file: FileLikeObject;
|
||||||
@@ -17,14 +18,12 @@ export class FileItem {
|
|||||||
public isSuccess: boolean = false;
|
public isSuccess: boolean = false;
|
||||||
public isCancel: boolean = false;
|
public isCancel: boolean = false;
|
||||||
public isError: boolean = false;
|
public isError: boolean = false;
|
||||||
|
public isRemoving: boolean = false;
|
||||||
public progress: number = 0;
|
public progress: number = 0;
|
||||||
public index: number = void 0;
|
public index: number = void 0;
|
||||||
public _xhr: XMLHttpRequest;
|
public downloadUrl?: string = null;
|
||||||
public _form: any;
|
public _form: any;
|
||||||
public _chunkUploaders: any = [];
|
|
||||||
public _fileChunks: FileChunk;
|
public _fileChunks: FileChunk;
|
||||||
public _currentChunk: number = 0;
|
|
||||||
public _totalChunks: number = 0;
|
|
||||||
|
|
||||||
protected chunkTotalRetries = 10;
|
protected chunkTotalRetries = 10;
|
||||||
protected chunkRetries = 0;
|
protected chunkRetries = 0;
|
||||||
@@ -45,19 +44,16 @@ export class FileItem {
|
|||||||
}
|
}
|
||||||
this.url = uploader.options.url;
|
this.url = uploader.options.url;
|
||||||
}
|
}
|
||||||
|
|
||||||
public upload(): void {
|
public upload(): void {
|
||||||
try {
|
try {
|
||||||
this.uploader.uploadItem(this);
|
this.uploader.uploadItem(this);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.uploader._onCompleteItem(this, '', 0, {});
|
this.uploader._onCompleteItem(this, '', 0, new HttpHeaders());
|
||||||
this.uploader._onErrorItem(this, '', 0, {});
|
this.uploader._onErrorItem(this, '', 0, new HttpHeaders());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public createFileChunk(chunkSize: number): void {
|
public createFileChunk(chunkSize: number): void {
|
||||||
this.fileChunks = new FileChunk(this._file, { byteStepSize: chunkSize });
|
this.fileChunks = new FileChunk(this._file, { byteStepSize: chunkSize });
|
||||||
this._currentChunk = this.fileChunks.currentChunk;
|
|
||||||
this._totalChunks = this.fileChunks.totalChunks;
|
|
||||||
}
|
}
|
||||||
public getCurrentChunkFile(): any {
|
public getCurrentChunkFile(): any {
|
||||||
return this.fileChunks.getCurrentRawFileChunk();
|
return this.fileChunks.getCurrentRawFileChunk();
|
||||||
@@ -65,10 +61,10 @@ export class FileItem {
|
|||||||
public prepareNextChunk(): void {
|
public prepareNextChunk(): void {
|
||||||
this.fileChunks.prepareNextChunk();
|
this.fileChunks.prepareNextChunk();
|
||||||
}
|
}
|
||||||
public getCurrentChunk():any{
|
public getCurrentChunk(): number {
|
||||||
return this.fileChunks.getCurrentChunk()
|
return this.fileChunks.getCurrentChunk()
|
||||||
}
|
}
|
||||||
public getTotalChunks():any{
|
public getTotalChunks(): number {
|
||||||
return this.fileChunks.getTotalChunks()
|
return this.fileChunks.getTotalChunks()
|
||||||
}
|
}
|
||||||
public setIsUploading(val: boolean) {
|
public setIsUploading(val: boolean) {
|
||||||
@@ -77,7 +73,6 @@ export class FileItem {
|
|||||||
this.fileChunks.setUploading(val)
|
this.fileChunks.setUploading(val)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public set fileChunks(val: FileChunk) {
|
public set fileChunks(val: FileChunk) {
|
||||||
this._fileChunks = val;
|
this._fileChunks = val;
|
||||||
}
|
}
|
||||||
@@ -93,42 +88,45 @@ export class FileItem {
|
|||||||
public cancel(): void {
|
public cancel(): void {
|
||||||
this.uploader.cancelItem(this);
|
this.uploader.cancelItem(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public remove(): void {
|
public remove(): void {
|
||||||
this.uploader.removeFromQueue(this);
|
this.uploader.removeFromQueue(this);
|
||||||
}
|
}
|
||||||
|
public removeOnline(): void {
|
||||||
|
this.isRemoving = true;
|
||||||
|
this.uploader.uploaderService.deleteEntry(this,{},true).subscribe(
|
||||||
|
(result:any) => {
|
||||||
|
this.isRemoving = false;
|
||||||
|
this.remove();
|
||||||
|
},
|
||||||
|
(error:any) => {
|
||||||
|
this.isRemoving = false;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
public onBeforeUpload(): void {
|
public onBeforeUpload(): void {
|
||||||
return void 0;
|
return void 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public onBuildForm(form: any): any {
|
public onBuildForm(form: any): any {
|
||||||
return { form };
|
return { form };
|
||||||
}
|
}
|
||||||
|
|
||||||
public onProgress(progress: number): any {
|
public onProgress(progress: number): any {
|
||||||
return { progress };
|
return { progress };
|
||||||
}
|
}
|
||||||
|
public onSuccess(response: string, status: number, headers: HttpHeaders): any {
|
||||||
public onSuccess(response: string, status: number, headers: ParsedResponseHeaders): any {
|
|
||||||
return { response, status, headers };
|
return { response, status, headers };
|
||||||
}
|
}
|
||||||
|
public onError(response: string, status: number, headers: HttpHeaders): any {
|
||||||
public onError(response: string, status: number, headers: ParsedResponseHeaders): any {
|
|
||||||
return { response, status, headers };
|
return { response, status, headers };
|
||||||
}
|
}
|
||||||
|
public onCancel(): any {
|
||||||
public onCancel(response: string, status: number, headers: ParsedResponseHeaders): any {
|
return {};
|
||||||
|
}
|
||||||
|
public onComplete(response: string, status: number, headers: HttpHeaders): any {
|
||||||
return { response, status, headers };
|
return { response, status, headers };
|
||||||
}
|
}
|
||||||
|
public onCompleteChunk(response: string, status: number, headers: HttpHeaders): any {
|
||||||
public onComplete(response: string, status: number, headers: ParsedResponseHeaders): any {
|
|
||||||
return { response, status, headers };
|
return { response, status, headers };
|
||||||
}
|
}
|
||||||
public onCompleteChunk(response: string, status: number, headers: ParsedResponseHeaders): any {
|
|
||||||
return { response, status, headers };
|
|
||||||
}
|
|
||||||
|
|
||||||
public _onBeforeUpload(): void {
|
public _onBeforeUpload(): void {
|
||||||
this.isReady = true;
|
this.isReady = true;
|
||||||
this.isUploading = true;
|
this.isUploading = true;
|
||||||
@@ -139,17 +137,14 @@ export class FileItem {
|
|||||||
this.progress = 0;
|
this.progress = 0;
|
||||||
this.onBeforeUpload();
|
this.onBeforeUpload();
|
||||||
}
|
}
|
||||||
|
|
||||||
public _onBuildForm(form: any): void {
|
public _onBuildForm(form: any): void {
|
||||||
this.onBuildForm(form);
|
this.onBuildForm(form);
|
||||||
}
|
}
|
||||||
|
|
||||||
public _onProgress(progress: number): void {
|
public _onProgress(progress: number): void {
|
||||||
this.progress = progress;
|
this.progress = progress;
|
||||||
this.onProgress(progress);
|
this.onProgress(progress);
|
||||||
}
|
}
|
||||||
|
public _onSuccess(response: string, status: number, headers: HttpHeaders): void {
|
||||||
public _onSuccess(response: string, status: number, headers: ParsedResponseHeaders): void {
|
|
||||||
this.isReady = false;
|
this.isReady = false;
|
||||||
this.isUploading = false;
|
this.isUploading = false;
|
||||||
this.isUploaded = true;
|
this.isUploaded = true;
|
||||||
@@ -160,8 +155,7 @@ export class FileItem {
|
|||||||
this.index = void 0;
|
this.index = void 0;
|
||||||
this.onSuccess(response, status, headers);
|
this.onSuccess(response, status, headers);
|
||||||
}
|
}
|
||||||
|
public _onError(response: string, status: number, headers: HttpHeaders): void {
|
||||||
public _onError(response: string, status: number, headers: ParsedResponseHeaders): void {
|
|
||||||
this.isReady = false;
|
this.isReady = false;
|
||||||
this.isUploading = false;
|
this.isUploading = false;
|
||||||
this.isUploaded = true;
|
this.isUploaded = true;
|
||||||
@@ -172,8 +166,7 @@ export class FileItem {
|
|||||||
this.index = void 0;
|
this.index = void 0;
|
||||||
this.onError(response, status, headers);
|
this.onError(response, status, headers);
|
||||||
}
|
}
|
||||||
|
public _onCancel(): void {
|
||||||
public _onCancel(response: string, status: number, headers: ParsedResponseHeaders): void {
|
|
||||||
this.isReady = false;
|
this.isReady = false;
|
||||||
this.isUploading = false;
|
this.isUploading = false;
|
||||||
this.isUploaded = false;
|
this.isUploaded = false;
|
||||||
@@ -182,25 +175,25 @@ export class FileItem {
|
|||||||
this.isError = false;
|
this.isError = false;
|
||||||
this.progress = 0;
|
this.progress = 0;
|
||||||
this.index = void 0;
|
this.index = void 0;
|
||||||
this.onCancel(response, status, headers);
|
this.onCancel();
|
||||||
}
|
}
|
||||||
|
public _onComplete(response: string, status: number, headers: HttpHeaders): void {
|
||||||
public _onComplete(response: string, status: number, headers: ParsedResponseHeaders): void {
|
|
||||||
this.onComplete(response, status, headers);
|
this.onComplete(response, status, headers);
|
||||||
|
|
||||||
if (this.uploader.options.removeAfterUpload) {
|
if (this.uploader.options.removeAfterUpload) {
|
||||||
this.remove();
|
this.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public _onCompleteChunk(response: string, status: number, headers: ParsedResponseHeaders): void {
|
public _onCompleteChunk(response: string, status: number, headers: HttpHeaders): void {
|
||||||
this.chunkRetries = 0;
|
this.chunkRetries = 0;
|
||||||
this._onCompleteChunkCallNext();
|
this._onCompleteChunkCallNext();
|
||||||
this.onCompleteChunk(response, status, headers);
|
this.onCompleteChunk(response, status, headers);
|
||||||
}
|
}
|
||||||
public _onCompleteChunkCallNext(): void {
|
public _onCompleteChunkCallNext(): void {
|
||||||
//Let's Retry to send this chunk 4 times;
|
this.uploader.uploaderService.uploadFile(this,this.uploader.options);
|
||||||
|
this.prepareNextChunk()
|
||||||
}
|
}
|
||||||
public _onErrorChunk(response: string, status: number, headers: ParsedResponseHeaders): void {
|
public _onErrorChunk(response: string, status: number, headers: HttpHeaders): void {
|
||||||
if (this.chunkRetries > this.chunkTotalRetries) {
|
if (this.chunkRetries > this.chunkTotalRetries) {
|
||||||
this.uploader.onErrorItem(this, response, status, headers);
|
this.uploader.onErrorItem(this, response, status, headers);
|
||||||
this.uploader.onCompleteItem(this, response, status, headers);
|
this.uploader.onCompleteItem(this, response, status, headers);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { FileLikeObject } from "../ng2-file-upload";
|
import { FileLikeObject } from "../ng2-chunk-file-upload";
|
||||||
|
|
||||||
export class FileType {
|
export class FileType {
|
||||||
/* MS office */
|
/* MS office */
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
|
import { Headers } from './file-uploader.class';
|
||||||
import { EventEmitter } from '@angular/core';
|
import { EventEmitter } from '@angular/core';
|
||||||
import { FileLikeObject } from './file-like-object.class';
|
import { FileLikeObject } from './file-like-object.class';
|
||||||
import { FileItem } from './file-item.class';
|
import { FileItem } from './file-item.class';
|
||||||
import { FileType } from './file-type.class';
|
import { FileType } from './file-type.class';
|
||||||
|
import { HttpEvent, HttpResponse, HttpHeaders } from '@angular/common/http';
|
||||||
|
import { HttpUploadProgressEvent, HttpProgressEvent, HttpSentEvent, HttpErrorResponse } from '@angular/common/http/src/response';
|
||||||
function isFile(value: any): boolean {
|
function isFile(value: any): boolean {
|
||||||
return (File && value instanceof File);
|
return (File && value instanceof File);
|
||||||
}
|
}
|
||||||
@@ -11,7 +14,6 @@ export interface Headers {
|
|||||||
value: string;
|
value: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ParsedResponseHeaders = { [ headerFieldName: string ]: string };
|
|
||||||
|
|
||||||
export type FilterFunction = {
|
export type FilterFunction = {
|
||||||
name: string,
|
name: string,
|
||||||
@@ -19,6 +21,7 @@ export type FilterFunction = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export interface FileUploaderOptions {
|
export interface FileUploaderOptions {
|
||||||
|
uploaderService: any;
|
||||||
allowedMimeType?: string[];
|
allowedMimeType?: string[];
|
||||||
allowedFileType?: string[];
|
allowedFileType?: string[];
|
||||||
autoUpload?: boolean;
|
autoUpload?: boolean;
|
||||||
@@ -38,15 +41,10 @@ export interface FileUploaderOptions {
|
|||||||
parametersBeforeFiles?: boolean;
|
parametersBeforeFiles?: boolean;
|
||||||
formatDataFunction?: Function;
|
formatDataFunction?: Function;
|
||||||
formatDataFunctionIsAsync?: boolean;
|
formatDataFunctionIsAsync?: boolean;
|
||||||
chunkSize?: number;
|
|
||||||
currentChunkParam?: string;
|
|
||||||
totalChunkParam?: string;
|
|
||||||
chunkMethod?: string;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export class FileUploader {
|
export class FileUploader {
|
||||||
|
public uploaderService: any;
|
||||||
public authToken: string;
|
public authToken: string;
|
||||||
public isUploading: boolean = false;
|
public isUploading: boolean = false;
|
||||||
public queue: FileItem[] = [];
|
public queue: FileItem[] = [];
|
||||||
@@ -56,17 +54,11 @@ export class FileUploader {
|
|||||||
public authTokenHeader: string;
|
public authTokenHeader: string;
|
||||||
public response: EventEmitter<any>;
|
public response: EventEmitter<any>;
|
||||||
public chunkSize: number = null;
|
public chunkSize: number = null;
|
||||||
public currentChunkParam: string = "current_chunk";
|
|
||||||
public totalChunkParam: string = "total_chunks";
|
|
||||||
public chunkMethod: string = "PUT";
|
|
||||||
public options: FileUploaderOptions = {
|
public options: FileUploaderOptions = {
|
||||||
|
uploaderService: null,
|
||||||
autoUpload: false,
|
autoUpload: false,
|
||||||
isHTML5: true,
|
isHTML5: true,
|
||||||
filters: [],
|
filters: [],
|
||||||
chunkSize: null,
|
|
||||||
currentChunkParam: "current_chunk",
|
|
||||||
totalChunkParam: "total_chunks",
|
|
||||||
chunkMethod: "PUT",
|
|
||||||
removeAfterUpload: false,
|
removeAfterUpload: false,
|
||||||
disableMultipart: false,
|
disableMultipart: false,
|
||||||
formatDataFunction: (item: FileItem) => item._file,
|
formatDataFunction: (item: FileItem) => item._file,
|
||||||
@@ -81,14 +73,11 @@ export class FileUploader {
|
|||||||
}
|
}
|
||||||
public setOptions(options: FileUploaderOptions): void {
|
public setOptions(options: FileUploaderOptions): void {
|
||||||
this.options = Object.assign(this.options, options);
|
this.options = Object.assign(this.options, options);
|
||||||
|
this.uploaderService = this.options.uploaderService;
|
||||||
|
this.uploaderService.uploader = this;
|
||||||
this.authToken = this.options.authToken;
|
this.authToken = this.options.authToken;
|
||||||
this.authTokenHeader = this.options.authTokenHeader || 'Authorization';
|
this.authTokenHeader = this.options.authTokenHeader || 'Authorization';
|
||||||
this.autoUpload = this.options.autoUpload;
|
this.autoUpload = this.options.autoUpload;
|
||||||
this.chunkSize = this.options.chunkSize;
|
|
||||||
this.currentChunkParam = this.options.currentChunkParam;
|
|
||||||
this.totalChunkParam = this.options.totalChunkParam;
|
|
||||||
this.chunkMethod = this.options.chunkMethod;
|
|
||||||
this.options.filters.unshift({ name: 'queueLimit', fn: this._queueLimitFilter });
|
this.options.filters.unshift({ name: 'queueLimit', fn: this._queueLimitFilter });
|
||||||
|
|
||||||
if (this.options.maxFileSize) {
|
if (this.options.maxFileSize) {
|
||||||
@@ -148,9 +137,9 @@ export class FileUploader {
|
|||||||
if (item.isUploading) {
|
if (item.isUploading) {
|
||||||
item.cancel();
|
item.cancel();
|
||||||
}
|
}
|
||||||
this.onRemoveItem(item);
|
|
||||||
this.queue.splice(index, 1);
|
this.queue.splice(index, 1);
|
||||||
this.progress = this._getTotalProgress();
|
this.progress = this._getTotalProgress();
|
||||||
|
this.onRemoveItem(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
public clearQueue(): void {
|
public clearQueue(): void {
|
||||||
@@ -163,21 +152,19 @@ export class FileUploader {
|
|||||||
public uploadItem(value: FileItem): void {
|
public uploadItem(value: FileItem): void {
|
||||||
let index = this.getIndexOfItem(value);
|
let index = this.getIndexOfItem(value);
|
||||||
let item = this.queue[index];
|
let item = this.queue[index];
|
||||||
let transport = this.options.isHTML5 ? '_xhrTransport' : '_iframeTransport';
|
|
||||||
item._prepareToUploading();
|
item._prepareToUploading();
|
||||||
if (this.isUploading) {
|
if (this.isUploading) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.isUploading = true;
|
this.isUploading = true;
|
||||||
(this as any)[ transport ](item);
|
this._uploadFile(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
public cancelItem(value: FileItem): void {
|
public cancelItem(value: FileItem): void {
|
||||||
const index = this.getIndexOfItem(value);
|
const index = this.getIndexOfItem(value);
|
||||||
const item = this.queue[index];
|
const item = this.queue[index];
|
||||||
const prop = this.options.isHTML5 ? item._xhr : item._form;
|
|
||||||
if (item && item.isUploading) {
|
if (item && item.isUploading) {
|
||||||
prop.abort();
|
this.uploaderService.stopUpload()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -266,27 +253,27 @@ export class FileUploader {
|
|||||||
return { progress };
|
return { progress };
|
||||||
}
|
}
|
||||||
|
|
||||||
public onSuccessItem(item: FileItem, response: string, status: number, headers: ParsedResponseHeaders): any {
|
public onSuccessItem(item: FileItem, response: string, status: number, headers: HttpHeaders): any {
|
||||||
return { item, response, status, headers };
|
return { item, response, status, headers };
|
||||||
}
|
}
|
||||||
|
|
||||||
public onErrorItem(item: FileItem, response: string, status: number, headers: ParsedResponseHeaders): any {
|
public onErrorItem(item: FileItem, response: string, status: number, headers: HttpHeaders): any {
|
||||||
return { item, response, status, headers };
|
return { item, response, status, headers };
|
||||||
}
|
}
|
||||||
|
|
||||||
public onCancelItem(item: FileItem, response: string, status: number, headers: ParsedResponseHeaders): any {
|
public onCancelItem(item: FileItem): any {
|
||||||
return { item, response, status, headers };
|
return { item };
|
||||||
}
|
}
|
||||||
public onRemoveItem(item: FileItem): any {
|
public onRemoveItem(item: FileItem): any {
|
||||||
return { item };
|
return { item };
|
||||||
}
|
}
|
||||||
public onCompleteChunk(item: FileItem, response: string, status: number, headers: ParsedResponseHeaders): any {
|
public onCompleteChunk(item: FileItem, response: string, status: number, headers: HttpHeaders): any {
|
||||||
return { item, response, status, headers };
|
return { item, response, status, headers };
|
||||||
}
|
}
|
||||||
public onErrorChunk(item: FileItem, response: string, status: number, headers: ParsedResponseHeaders): any {
|
public onErrorChunk(item: FileItem, response: string, status: number, headers: HttpHeaders): any {
|
||||||
return { item, response, status, headers };
|
return { item, response, status, headers };
|
||||||
}
|
}
|
||||||
public onCompleteItem(item: FileItem, response: string, status: number, headers: ParsedResponseHeaders): any {
|
public onCompleteItem(item: FileItem, response: string, status: number, headers: HttpHeaders): any {
|
||||||
return { item, response, status, headers };
|
return { item, response, status, headers };
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -307,17 +294,17 @@ export class FileUploader {
|
|||||||
this.options.allowedFileType.indexOf(FileType.getMimeClass(item)) === -1);
|
this.options.allowedFileType.indexOf(FileType.getMimeClass(item)) === -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public _onErrorItem(item: FileItem, response: string, status: number, headers: ParsedResponseHeaders): void {
|
public _onErrorItem(item: FileItem, response: string, status: number, headers: HttpHeaders): void {
|
||||||
item._onError(response, status, headers);
|
item._onError(response, status, headers);
|
||||||
this.onErrorItem(item, response, status, headers);
|
this.onErrorItem(item, response, status, headers);
|
||||||
}
|
}
|
||||||
public _onCompleteChunk(item: FileItem, response: string, status: number, headers: ParsedResponseHeaders): void{
|
public _onCompleteChunk(item: FileItem, response: string, status: number, headers: HttpHeaders): void {
|
||||||
this.onCompleteChunk(item, response, status, headers);
|
this.onCompleteChunk(item, response, status, headers);
|
||||||
item._onCompleteChunk(response, status, headers);
|
item._onCompleteChunk(response, status, headers);
|
||||||
this.progress = this._getTotalProgress();
|
this.progress = this._getTotalProgress();
|
||||||
this._render();
|
this._render();
|
||||||
}
|
}
|
||||||
public _onCompleteItem(item: FileItem, response: string, status: number, headers: ParsedResponseHeaders): void {
|
public _onCompleteItem(item: FileItem, response?: string, status?: number, headers?: HttpHeaders): void {
|
||||||
item._onComplete(response, status, headers);
|
item._onComplete(response, status, headers);
|
||||||
this.onCompleteItem(item, response, status, headers);
|
this.onCompleteItem(item, response, status, headers);
|
||||||
let nextItem = this.getReadyItems()[0];
|
let nextItem = this.getReadyItems()[0];
|
||||||
@@ -330,169 +317,75 @@ export class FileUploader {
|
|||||||
this.progress = this._getTotalProgress();
|
this.progress = this._getTotalProgress();
|
||||||
this._render();
|
this._render();
|
||||||
}
|
}
|
||||||
protected _headersGetter(parsedHeaders: ParsedResponseHeaders): any {
|
|
||||||
return (name: any): any => {
|
protected _onProgress(event: HttpProgressEvent, item: FileItem) {
|
||||||
if (name) {
|
event = event;
|
||||||
return parsedHeaders[ name.toLowerCase() ] || void 0;
|
let progress = (100 * event.loaded / event.total);
|
||||||
|
if (this.uploaderService.options.chunkSize > 0) {
|
||||||
|
progress = ( 100 * item.getCurrentChunk() / item.getTotalChunks() ) + (progress / item.getTotalChunks() );
|
||||||
}
|
}
|
||||||
return parsedHeaders;
|
// TODO: Check why it's not showing upload progress per item only on complete.
|
||||||
};
|
this._onProgressItem(item, Math.round(progress) );
|
||||||
}
|
}
|
||||||
protected _xhrAppendEvents(xhr: XMLHttpRequest, item: FileItem): XMLHttpRequest{
|
public onProgress(event: HttpProgressEvent, item: FileItem) {
|
||||||
let that = this;
|
this._onProgress(event, item);
|
||||||
xhr.upload.onprogress = (event: any) => {
|
|
||||||
let progress = Math.round(event.lengthComputable ? event.loaded * 100 / event.total : 0);
|
|
||||||
if (that.options.chunkSize > 0) {
|
|
||||||
progress = Math.round( ((item._currentChunk-1) * 100) / item._totalChunks) + Math.round(progress / item._totalChunks);
|
|
||||||
}
|
}
|
||||||
this._onProgressItem(item, progress);
|
protected _onStart(event: HttpSentEvent, item: FileItem) {
|
||||||
};
|
|
||||||
xhr.onload = () => {
|
}
|
||||||
const headers = this._parseHeaders(xhr.getAllResponseHeaders());
|
public onStart(event: HttpSentEvent, item: FileItem) {
|
||||||
const response = this._transformResponse(xhr.response, headers);
|
this._onStart(event, item);
|
||||||
const gist = this._isSuccessCode(xhr.status) ? 'Success' : 'Error';
|
}
|
||||||
|
protected _onLoad(event: HttpResponse<any>, item: FileItem) {
|
||||||
|
const headers = event.headers;
|
||||||
|
const response = this._transformResponse(event.body, headers);
|
||||||
|
const gist = this._isSuccessCode(event.status) ? 'Success' : 'Error';
|
||||||
const method = '_on' + gist + 'Item';
|
const method = '_on' + gist + 'Item';
|
||||||
if (this.options.chunkSize > 0) {
|
if (this.uploaderService.options.chunkSize > 0) {
|
||||||
item._chunkUploaders.pop();
|
if ( (item.getCurrentChunk() +1) >= item.getTotalChunks()) {
|
||||||
if (item._currentChunk >= item._totalChunks) {
|
(this as any)[method](item, response, event.status, headers);
|
||||||
(this as any)[ method ](item, response, xhr.status, headers);
|
this._onCompleteItem(item, response, event.status, headers);
|
||||||
this._onCompleteItem(item, response, xhr.status, headers);
|
|
||||||
} else {
|
} else {
|
||||||
this._onCompleteChunk(item, response, xhr.status, headers);
|
this._onCompleteChunk(item, response, event.status, headers);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
(this as any)[ method ](item, response, xhr.status, headers);
|
(this as any)[method](item, response, event.status, headers);
|
||||||
this._onCompleteItem(item, response, xhr.status, headers);
|
this._onCompleteItem(item, response, event.status, headers);
|
||||||
}
|
}
|
||||||
};
|
|
||||||
xhr.onerror = () => {
|
}
|
||||||
const headers = this._parseHeaders(xhr.getAllResponseHeaders());
|
public onLoad(event: HttpResponse<any>, item: FileItem) {
|
||||||
const response = this._transformResponse(xhr.response, headers);
|
this._onLoad(event, item);
|
||||||
if (this.options.chunkSize > 0) {
|
}
|
||||||
this._onErrorChunk(item, response, xhr.status, headers);
|
|
||||||
|
protected _onError(error: any, item: FileItem) {
|
||||||
|
const headers: HttpHeaders = error.Headers
|
||||||
|
const response = this._transformResponse(error.error, headers);
|
||||||
|
if (this.uploaderService.options.chunkSize > 0) {
|
||||||
|
this._onErrorChunk(item, response, error.status, headers);
|
||||||
} else {
|
} else {
|
||||||
this._onErrorItem(item, response, xhr.status, headers);
|
this._onErrorItem(item, response, error.status, headers);
|
||||||
this._onCompleteItem(item, response, xhr.status, headers);
|
this._onCompleteItem(item, response, error.status, headers);
|
||||||
}
|
|
||||||
};
|
|
||||||
xhr.onabort = () => {
|
|
||||||
const headers = this._parseHeaders(xhr.getAllResponseHeaders());
|
|
||||||
const response = this._transformResponse(xhr.response, headers);
|
|
||||||
this._onCancelItem(item, response, xhr.status, headers);
|
|
||||||
this._onCompleteItem(item, response, xhr.status, headers);
|
|
||||||
};
|
|
||||||
|
|
||||||
xhr.open(item.method, item.url, true);
|
|
||||||
xhr.withCredentials = item.withCredentials;
|
|
||||||
if (this.options.headers) {
|
|
||||||
for (let header of this.options.headers) {
|
|
||||||
xhr.setRequestHeader(header.name, header.value);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (item.headers.length) {
|
public onError(error: HttpErrorResponse, item: FileItem) {
|
||||||
for (let header of item.headers) {
|
this._onError(error,item);
|
||||||
xhr.setRequestHeader(header.name, header.value);
|
|
||||||
}
|
}
|
||||||
}
|
protected _onAbort(error: HttpErrorResponse, item: FileItem) {
|
||||||
if (this.authToken) {
|
this._onCancelItem(item);
|
||||||
xhr.setRequestHeader(this.authTokenHeader, this.authToken);
|
this._onCompleteItem(item);
|
||||||
}
|
|
||||||
xhr.onreadystatechange = function () {
|
|
||||||
if (xhr.readyState == XMLHttpRequest.DONE) {
|
|
||||||
that.response.emit(xhr.responseText)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
return xhr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected _buildMultiPartSendable(item: FileItem): FormData{
|
public onAbort(error: HttpErrorResponse, item: FileItem) {
|
||||||
let sendable: FormData;
|
this._onAbort(error, item);
|
||||||
sendable = new FormData();
|
|
||||||
this._onBuildItemForm(item, sendable);
|
|
||||||
let file: any = null;
|
|
||||||
if(this.options.chunkSize > 0){
|
|
||||||
file = item.getCurrentChunkFile();
|
|
||||||
}else{
|
|
||||||
file = item._file;
|
|
||||||
}
|
|
||||||
const appendFile = () => sendable.append(item.alias, file, item.file.name);
|
|
||||||
if (!this.options.parametersBeforeFiles) {
|
|
||||||
appendFile();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// For AWS, Additional Parameters must come BEFORE Files
|
protected _uploadFile(item: FileItem): any {
|
||||||
if (this.options.additionalParameter !== undefined) {
|
|
||||||
Object.keys(this.options.additionalParameter).forEach((key: string) => {
|
|
||||||
let paramVal = this.options.additionalParameter[ key ];
|
|
||||||
// Allow an additional parameter to include the filename
|
|
||||||
if (typeof paramVal === 'string' && paramVal.indexOf('{{file_name}}') >= 0) {
|
|
||||||
paramVal = paramVal.replace('{{file_name}}', item.file.name);
|
|
||||||
}
|
|
||||||
sendable.append(key, paramVal);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if (this.options.chunkSize > 0 && this.options.totalChunkParam){
|
|
||||||
sendable.append(this.options.totalChunkParam,item.getTotalChunks());
|
|
||||||
}
|
|
||||||
if (this.options.chunkSize > 0 && this.options.currentChunkParam){
|
|
||||||
sendable.append(this.options.currentChunkParam,item.getCurrentChunk() +1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.options.parametersBeforeFiles) {
|
|
||||||
appendFile();
|
|
||||||
}
|
|
||||||
|
|
||||||
return sendable;
|
|
||||||
}
|
|
||||||
protected _xhrTransport(item: FileItem): any {
|
|
||||||
let that = this;
|
|
||||||
let xhr = item._xhr = new XMLHttpRequest();
|
|
||||||
let sendable: any;
|
|
||||||
this._onBeforeUploadItem(item);
|
this._onBeforeUploadItem(item);
|
||||||
|
|
||||||
if (typeof item._file.size !== 'number') {
|
if (typeof item._file.size !== 'number') {
|
||||||
throw new TypeError('The file specified is no longer valid');
|
throw new TypeError('The file specified is no longer valid');
|
||||||
}
|
}
|
||||||
if (!this.options.disableMultipart) {
|
this.uploaderService.uploadFile(item, this.options);
|
||||||
/* CHUNCKED FILE UPLOAD */
|
|
||||||
if (this.options.chunkSize > 0) {
|
|
||||||
const chunkMethod = this.options.chunkMethod;
|
|
||||||
item._chunkUploaders = [];
|
|
||||||
item._currentChunk = 0;
|
|
||||||
item._onCompleteChunkCallNext = function(): void{
|
|
||||||
item._currentChunk ++;
|
|
||||||
if (item._currentChunk > 1) {
|
|
||||||
item.method = chunkMethod;
|
|
||||||
}
|
|
||||||
const sendable = this.uploader._buildMultiPartSendable(item);
|
|
||||||
let xhr = new XMLHttpRequest();
|
|
||||||
xhr = this.uploader._xhrAppendEvents(xhr, item);
|
|
||||||
item._xhr = xhr;
|
|
||||||
item._chunkUploaders.push(xhr);
|
|
||||||
xhr.send(sendable);
|
|
||||||
item.prepareNextChunk()
|
|
||||||
};
|
|
||||||
item.createFileChunk(this.options.chunkSize);
|
|
||||||
item.setIsUploading(true);
|
|
||||||
item._onCompleteChunkCallNext();
|
|
||||||
this._render();
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
sendable = this._buildMultiPartSendable(item);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
sendable = this.options.formatDataFunction(item);
|
|
||||||
}
|
|
||||||
// Append Evenets
|
|
||||||
xhr = this._xhrAppendEvents(xhr, item);
|
|
||||||
if (this.options.formatDataFunctionIsAsync) {
|
|
||||||
sendable.then(
|
|
||||||
(result: any) => xhr.send(JSON.stringify(result))
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
xhr.send(sendable);
|
|
||||||
}
|
|
||||||
this._render();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected _getTotalProgress(value: number = 0): number {
|
protected _getTotalProgress(value: number = 0): number {
|
||||||
@@ -541,29 +434,10 @@ export class FileUploader {
|
|||||||
return (status >= 200 && status < 300) || status === 304;
|
return (status >= 200 && status < 300) || status === 304;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected _transformResponse(response: string, headers: ParsedResponseHeaders): string {
|
protected _transformResponse(response: string, headers: HttpHeaders): string {
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected _parseHeaders(headers: string): ParsedResponseHeaders {
|
|
||||||
let parsed: any = {};
|
|
||||||
let key: any;
|
|
||||||
let val: any;
|
|
||||||
let i: any;
|
|
||||||
if (!headers) {
|
|
||||||
return parsed;
|
|
||||||
}
|
|
||||||
headers.split('\n').map((line: any) => {
|
|
||||||
i = line.indexOf(':');
|
|
||||||
key = line.slice(0, i).trim().toLowerCase();
|
|
||||||
val = line.slice(i + 1).trim();
|
|
||||||
if (key) {
|
|
||||||
parsed[ key ] = parsed[ key ] ? parsed[ key ] + ', ' + val : val;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return parsed;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected _onWhenAddingFileFailed(item: FileLikeObject, filter: any, options: any): void {
|
protected _onWhenAddingFileFailed(item: FileLikeObject, filter: any, options: any): void {
|
||||||
this.onWhenAddingFileFailed(item, filter, options);
|
this.onWhenAddingFileFailed(item, filter, options);
|
||||||
}
|
}
|
||||||
@@ -581,7 +455,7 @@ export class FileUploader {
|
|||||||
this.onBeforeUploadItem(item);
|
this.onBeforeUploadItem(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected _onBuildItemForm(item: FileItem, form: any): void {
|
public _onBuildItemForm(item: FileItem, form: any): void {
|
||||||
item._onBuildForm(form);
|
item._onBuildForm(form);
|
||||||
this.onBuildItemForm(item, form);
|
this.onBuildItemForm(item, form);
|
||||||
}
|
}
|
||||||
@@ -594,17 +468,17 @@ export class FileUploader {
|
|||||||
this.onProgressAll(total);
|
this.onProgressAll(total);
|
||||||
this._render();
|
this._render();
|
||||||
}
|
}
|
||||||
protected _onErrorChunk(item: FileItem, response: string, status: number, headers: ParsedResponseHeaders): void {
|
protected _onErrorChunk(item: FileItem, response: string, status: number, headers: HttpHeaders): void {
|
||||||
item._onErrorChunk(response, status, headers);
|
item._onErrorChunk(response, status, headers);
|
||||||
this.onErrorChunk(item, response, status, headers)
|
this.onErrorChunk(item, response, status, headers)
|
||||||
}
|
}
|
||||||
protected _onSuccessItem(item: FileItem, response: string, status: number, headers: ParsedResponseHeaders): void {
|
protected _onSuccessItem(item: FileItem, response: string, status: number, headers: HttpHeaders): void {
|
||||||
item._onSuccess(response, status, headers);
|
item._onSuccess(response, status, headers);
|
||||||
this.onSuccessItem(item, response, status, headers);
|
this.onSuccessItem(item, response, status, headers);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected _onCancelItem(item: FileItem, response: string, status: number, headers: ParsedResponseHeaders): void {
|
protected _onCancelItem(item: FileItem): void {
|
||||||
item._onCancel(response, status, headers);
|
item._onCancel();
|
||||||
this.onCancelItem(item, response, status, headers);
|
this.onCancelItem(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
336
src/file-upload/file-uploader.service.ts
Normal file
336
src/file-upload/file-uploader.service.ts
Normal file
@@ -0,0 +1,336 @@
|
|||||||
|
import { map } from 'rxjs/operators/map';
|
||||||
|
import { Observable } from 'rxjs';
|
||||||
|
import { FileUploaderOptions, FileUploader } from './file-uploader.class';
|
||||||
|
import { FileItem } from './file-item.class';
|
||||||
|
import { HttpClient, HttpRequest, HttpEventType, HttpEvent, HttpErrorResponse, HttpHeaders, HttpParams } from '@angular/common/http';
|
||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
import { tap, last, catchError } from 'rxjs/operators';
|
||||||
|
import { of } from 'rxjs/observable/of';
|
||||||
|
|
||||||
|
export interface UploaderLinksOptions {
|
||||||
|
downloadEntry: string,
|
||||||
|
updateEntry: string,
|
||||||
|
createEntry: string,
|
||||||
|
deleteEntry: string,
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface UploaderServiceOptions {
|
||||||
|
createMethod: string;
|
||||||
|
updateMethod: string;
|
||||||
|
authorizationHeaderName?: string;
|
||||||
|
tokenPattern?: string;
|
||||||
|
token?: string;
|
||||||
|
chunkSize?: number;
|
||||||
|
totalChunkParamName?: string;
|
||||||
|
currentChunkParamName?: string;
|
||||||
|
fileParamName?: string;
|
||||||
|
idAttribute?: string;
|
||||||
|
}
|
||||||
|
@Injectable()
|
||||||
|
export class FileUploaderService {
|
||||||
|
public defaultLinks: UploaderLinksOptions = {
|
||||||
|
downloadEntry: '',
|
||||||
|
updateEntry: '',
|
||||||
|
createEntry: '',
|
||||||
|
deleteEntry: '',
|
||||||
|
}
|
||||||
|
public defaultOptions: UploaderServiceOptions = {
|
||||||
|
createMethod: 'POST',
|
||||||
|
updateMethod: 'POST',
|
||||||
|
authorizationHeaderName: "Authorization",
|
||||||
|
tokenPattern: null,
|
||||||
|
token: null,
|
||||||
|
chunkSize: 0,
|
||||||
|
totalChunkParamName: 'total_chunks',
|
||||||
|
currentChunkParamName: 'current_chunk',
|
||||||
|
fileParamName: 'file',
|
||||||
|
idAttribute: 'id',
|
||||||
|
}
|
||||||
|
public additionalHeaders = {};
|
||||||
|
protected cancelError = "UPLOAD CANCELED";
|
||||||
|
protected uploadSubscription: any = null;
|
||||||
|
public links:UploaderLinksOptions;
|
||||||
|
public options:UploaderServiceOptions;
|
||||||
|
private _uploader:FileUploader = null;
|
||||||
|
constructor(
|
||||||
|
protected http: HttpClient
|
||||||
|
){
|
||||||
|
this.links = Object.assign({}, this.defaultLinks, this.links);
|
||||||
|
this.options = Object.assign({}, this.defaultOptions, this.options);
|
||||||
|
}
|
||||||
|
get uploader():FileUploader {
|
||||||
|
return this._uploader;
|
||||||
|
}
|
||||||
|
set uploader(theUploader:FileUploader) {
|
||||||
|
this._uploader = theUploader;
|
||||||
|
}
|
||||||
|
public onBeforeUpload(item:FileItem, options:FileUploaderOptions):Promise<any>{
|
||||||
|
const promise = new Promise((resolve, reject) => {
|
||||||
|
resolve(true);
|
||||||
|
});
|
||||||
|
return promise;
|
||||||
|
}
|
||||||
|
public uploadFile(item:FileItem, options:FileUploaderOptions):void{
|
||||||
|
this.onBeforeUpload(item,options).then(
|
||||||
|
() => {
|
||||||
|
this._uploadFile(item, options);
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
public onBeforeGetDefaultHeaders(): Promise<any> {
|
||||||
|
const promise = new Promise((resolve, reject) => {
|
||||||
|
resolve(true);
|
||||||
|
});
|
||||||
|
return promise;
|
||||||
|
}
|
||||||
|
protected _getDefaultHeaders(): Promise<any>{
|
||||||
|
return new Promise((resolve,reject) => {
|
||||||
|
this.onBeforeGetDefaultHeaders().then(
|
||||||
|
(result) => {
|
||||||
|
const h:any = {}
|
||||||
|
if (this.options.tokenPattern && this.options.token) {
|
||||||
|
h[this.options.authorizationHeaderName] = this.options.tokenPattern.replace("#token#", this.options.token);
|
||||||
|
}
|
||||||
|
for (const key in this.additionalHeaders) {
|
||||||
|
if (this.additionalHeaders.hasOwnProperty(key)) {
|
||||||
|
h[key] = this.additionalHeaders[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
resolve(h);
|
||||||
|
},
|
||||||
|
(error) => {
|
||||||
|
reject(error);
|
||||||
|
}
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
protected _getRequestHeaders(item: FileItem, options: FileUploaderOptions): Promise<any> {
|
||||||
|
return new Promise((resolve,reject) => {
|
||||||
|
this._getDefaultHeaders().then(
|
||||||
|
(h) => {
|
||||||
|
if (options.headers) {
|
||||||
|
for (let header of options.headers) {
|
||||||
|
h[header.name] = header.value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (item.headers.length) {
|
||||||
|
for (let header of item.headers) {
|
||||||
|
h[header.name] = header.value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
resolve(h);
|
||||||
|
},
|
||||||
|
(error) => {
|
||||||
|
reject(error)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
public buildPackageToSend(item:FileItem, options:FileUploaderOptions){
|
||||||
|
let sendable: FormData = new FormData();
|
||||||
|
this.uploader._onBuildItemForm(item, sendable);
|
||||||
|
let file: any = null;
|
||||||
|
if (this.options.chunkSize > 0) {
|
||||||
|
file = item.getCurrentChunkFile();
|
||||||
|
} else {
|
||||||
|
file = item._file;
|
||||||
|
}
|
||||||
|
const appendFile = () => sendable.append(this.options.fileParamName, file, item.file.name);
|
||||||
|
if (!options.parametersBeforeFiles) {
|
||||||
|
appendFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
// For AWS, Additional Parameters must come BEFORE Files
|
||||||
|
if (options.additionalParameter !== undefined) {
|
||||||
|
Object.keys(options.additionalParameter).forEach((key: string) => {
|
||||||
|
let paramVal = options.additionalParameter[key];
|
||||||
|
// Allow an additional parameter to include the filename
|
||||||
|
if (typeof paramVal === 'string' && paramVal.indexOf('{{file_name}}') >= 0) {
|
||||||
|
paramVal = paramVal.replace('{{file_name}}', item.file.name);
|
||||||
|
}
|
||||||
|
sendable.append(key, paramVal);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.options.chunkSize > 0 && this.options.totalChunkParamName) {
|
||||||
|
sendable.append(this.options.totalChunkParamName, item.getTotalChunks().toString());
|
||||||
|
}
|
||||||
|
if (this.options.chunkSize > 0 && this.options.currentChunkParamName) {
|
||||||
|
sendable.append(this.options.currentChunkParamName, (item.getCurrentChunk() + 1).toString() );
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options.parametersBeforeFiles) {
|
||||||
|
appendFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
return sendable;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected _uploadFile(item:FileItem, options:FileUploaderOptions):void{
|
||||||
|
this._getRequestHeaders(item, options).then(
|
||||||
|
(headers) => {
|
||||||
|
let request_method = this.options.createMethod;
|
||||||
|
let link = this.links.createEntry;
|
||||||
|
item.setIsUploading(true);
|
||||||
|
if(this.options.chunkSize > 0){
|
||||||
|
try{
|
||||||
|
item.getCurrentChunk()
|
||||||
|
}catch(err){
|
||||||
|
item.createFileChunk(this.options.chunkSize);
|
||||||
|
}
|
||||||
|
request_method = item.getCurrentChunk() > 0 ? this.options.updateMethod : this.options.createMethod;
|
||||||
|
link = item.getCurrentChunk() > 0 ? this.links.updateEntry : this.links.createEntry;
|
||||||
|
}
|
||||||
|
if (item.getId()){
|
||||||
|
link = link.replace("#id#", item.getId());
|
||||||
|
}
|
||||||
|
const data = this.buildPackageToSend(item, options);
|
||||||
|
let request = new HttpRequest(request_method, link, data, {
|
||||||
|
headers: new HttpHeaders(headers),
|
||||||
|
reportProgress: true,
|
||||||
|
withCredentials: item.withCredentials,
|
||||||
|
});
|
||||||
|
this.uploadSubscription = this.http.request(request).subscribe(
|
||||||
|
(event) => {
|
||||||
|
this.getEventMessage(event, item);
|
||||||
|
},
|
||||||
|
(error) => {
|
||||||
|
if(this.cancelError === error){
|
||||||
|
this.uploader.onAbort(error, item);
|
||||||
|
}else{
|
||||||
|
this.uploader.onError(error, item);
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
)
|
||||||
|
},
|
||||||
|
(error) =>{
|
||||||
|
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
public stopUpload() {
|
||||||
|
if(this.uploadSubscription && this.uploadSubscription.unsubscribe){
|
||||||
|
this.uploadSubscription.error(this.cancelError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private getEventMessage(event: any, item: FileItem) {
|
||||||
|
switch (event.type) {
|
||||||
|
case HttpEventType.ResponseHeader:
|
||||||
|
break;
|
||||||
|
case HttpEventType.Sent:
|
||||||
|
this.uploader.onStart(event, item);
|
||||||
|
break;
|
||||||
|
case HttpEventType.UploadProgress:
|
||||||
|
this.uploader.onProgress(event, item);
|
||||||
|
break;
|
||||||
|
case HttpEventType.Response:
|
||||||
|
if(this.options.chunkSize > 0){
|
||||||
|
if(item.getCurrentChunk() === 0) {
|
||||||
|
const response = event.body;
|
||||||
|
if(response[this.options.idAttribute]) {
|
||||||
|
item.setId(response[this.options.idAttribute])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.uploader.onLoad(event, item);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private handleError(item: FileItem) {
|
||||||
|
const userMessage = `${item.file.name} upload failed.`;
|
||||||
|
|
||||||
|
return (error: HttpErrorResponse) => {
|
||||||
|
this.uploader.onError(error, item);
|
||||||
|
|
||||||
|
const message = (error.error instanceof Error) ?
|
||||||
|
error.error.message :
|
||||||
|
`server returned code ${error.status} with body "${error.error}"`;
|
||||||
|
|
||||||
|
return of(userMessage);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public deleteEntry(item: FileItem, options = {}, skipConfirmation = false): Observable<any>{
|
||||||
|
if(item.getId() && this.links['deleteEntry']){
|
||||||
|
let link = this.links['deleteEntry'].replace(/#id#/g, item.getId());
|
||||||
|
let confirmation = false;
|
||||||
|
if(skipConfirmation){
|
||||||
|
confirmation = true;
|
||||||
|
} else {
|
||||||
|
confirmation = confirm("Are you sure you want to delete this entry?")
|
||||||
|
}
|
||||||
|
|
||||||
|
if (confirmation) {
|
||||||
|
return this.delete(link, options).map(
|
||||||
|
(response: Response) => {
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
return Observable.of(false);
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
return Observable.of(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected delete(url: string, options = {}): Observable<any> {
|
||||||
|
return new Observable(
|
||||||
|
(observe) => {
|
||||||
|
this._getDefaultHeaders().then(
|
||||||
|
function(headers){
|
||||||
|
return this.http.delete(url, {headers: new HttpHeaders(headers) }).subscribe(
|
||||||
|
(response: Response) => {
|
||||||
|
observe.next(response);
|
||||||
|
},
|
||||||
|
(error) => {
|
||||||
|
observe.error(error);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}.bind(this),
|
||||||
|
(error) => {
|
||||||
|
observe.error(error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
HTTP General methos only bellow
|
||||||
|
*/
|
||||||
|
protected get(url: string): Observable<any>{
|
||||||
|
return new Observable(
|
||||||
|
(observe) => {
|
||||||
|
this._getDefaultHeaders().then(
|
||||||
|
function(headers){
|
||||||
|
return this.http.get(url, {headers: new HttpHeaders(headers) }).subscribe(
|
||||||
|
(response: Response) => {
|
||||||
|
observe.next(response);
|
||||||
|
},
|
||||||
|
(error) => {
|
||||||
|
observe.error(error);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}.bind(this),
|
||||||
|
(error) => {
|
||||||
|
observe.error(error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
public addHeader(name=null, value=null){
|
||||||
|
this.additionalHeaders[name] = value
|
||||||
|
}
|
||||||
|
|
||||||
|
public removeHeader(name=null){
|
||||||
|
if(this.additionalHeaders.hasOwnProperty(name)){
|
||||||
|
delete(this.additionalHeaders[name])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,5 +3,6 @@ export * from './file-upload/file-drop.directive';
|
|||||||
export * from './file-upload/file-uploader.class';
|
export * from './file-upload/file-uploader.class';
|
||||||
export * from './file-upload/file-item.class';
|
export * from './file-upload/file-item.class';
|
||||||
export * from './file-upload/file-like-object.class';
|
export * from './file-upload/file-like-object.class';
|
||||||
|
export * from './file-upload/file-uploader.service';
|
||||||
|
|
||||||
export { FileUploadModule } from './file-upload/file-upload.module';
|
export { FileUploadModule } from './file-upload/file-upload.module';
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "ng2-file-upload",
|
"name": "ng2-chunk-file-upload",
|
||||||
"version": "1.3.0",
|
"version": "1.3.0",
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@angular/common": "*",
|
"@angular/common": "*",
|
||||||
|
|||||||
@@ -28,7 +28,7 @@
|
|||||||
],
|
],
|
||||||
"files": [
|
"files": [
|
||||||
"../scripts/typings.d.ts",
|
"../scripts/typings.d.ts",
|
||||||
"./ng2-file-upload.ts",
|
"./ng2-chunk-file-upload.ts",
|
||||||
"./index.ts"
|
"./index.ts"
|
||||||
],
|
],
|
||||||
"angularCompilerOptions": {
|
"angularCompilerOptions": {
|
||||||
|
|||||||
24
tsconfig.json
Normal file
24
tsconfig.json
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
{
|
||||||
|
"compileOnSave": false,
|
||||||
|
"compilerOptions": {
|
||||||
|
"outDir": "./dist/out-tsc",
|
||||||
|
"sourceMap": true,
|
||||||
|
"declaration": false,
|
||||||
|
"moduleResolution": "node",
|
||||||
|
"emitDecoratorMetadata": true,
|
||||||
|
"experimentalDecorators": true,
|
||||||
|
"target": "es5",
|
||||||
|
"typeRoots": [
|
||||||
|
"node_modules/@types"
|
||||||
|
],
|
||||||
|
"lib": [
|
||||||
|
"es2017",
|
||||||
|
"dom"
|
||||||
|
],
|
||||||
|
"plugins": [
|
||||||
|
{
|
||||||
|
"name": "tslint-language-service"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
141
tslint.json
141
tslint.json
@@ -1,12 +1,137 @@
|
|||||||
{
|
{
|
||||||
"extends": "tslint-config-valorsoft",
|
"rulesDirectory": [
|
||||||
"rulesDirectory": "./node_modules/codelyzer",
|
"node_modules/codelyzer"
|
||||||
|
],
|
||||||
"rules": {
|
"rules": {
|
||||||
"no-forward-ref": false,
|
"trailing-comma": [
|
||||||
"no-null-keyword": false,
|
true,
|
||||||
"only-arrow-functions": false,
|
{
|
||||||
"no-access-missing-member": false,
|
"multiline": "always",
|
||||||
"directive-selector": false,
|
"singleline": "never"
|
||||||
"component-selector": false
|
}
|
||||||
|
],
|
||||||
|
"arrow-return-shorthand": true,
|
||||||
|
"callable-types": true,
|
||||||
|
"class-name": true,
|
||||||
|
"comment-format": [
|
||||||
|
true,
|
||||||
|
"check-space"
|
||||||
|
],
|
||||||
|
"eofline": true,
|
||||||
|
"forin": true,
|
||||||
|
"import-blacklist": [
|
||||||
|
true,
|
||||||
|
"rxjs"
|
||||||
|
],
|
||||||
|
"import-spacing": true,
|
||||||
|
"indent": [
|
||||||
|
true,
|
||||||
|
"tabs",
|
||||||
|
4
|
||||||
|
],
|
||||||
|
"interface-over-type-literal": true,
|
||||||
|
"label-position": true,
|
||||||
|
"max-line-length": [
|
||||||
|
true,
|
||||||
|
180
|
||||||
|
],
|
||||||
|
"member-access": false,
|
||||||
|
"no-arg": true,
|
||||||
|
"no-console": [
|
||||||
|
true,
|
||||||
|
"debug",
|
||||||
|
"log",
|
||||||
|
"time",
|
||||||
|
"timeEnd",
|
||||||
|
"trace"
|
||||||
|
],
|
||||||
|
"no-construct": true,
|
||||||
|
"no-debugger": true,
|
||||||
|
"no-duplicate-super": true,
|
||||||
|
"no-empty": false,
|
||||||
|
"no-empty-interface": true,
|
||||||
|
"no-eval": true,
|
||||||
|
"no-misused-new": true,
|
||||||
|
"no-non-null-assertion": true,
|
||||||
|
"no-shadowed-variable": true,
|
||||||
|
"no-string-literal": false,
|
||||||
|
"no-string-throw": true,
|
||||||
|
"no-switch-case-fall-through": true,
|
||||||
|
"no-trailing-whitespace": true,
|
||||||
|
"no-unnecessary-initializer": true,
|
||||||
|
"no-use-before-declare": true,
|
||||||
|
"no-var-keyword": true,
|
||||||
|
"object-literal-sort-keys": false,
|
||||||
|
"one-line": [
|
||||||
|
true,
|
||||||
|
"check-open-brace",
|
||||||
|
"check-catch",
|
||||||
|
"check-else",
|
||||||
|
"check-whitespace"
|
||||||
|
],
|
||||||
|
"prefer-const": true,
|
||||||
|
"quotemark": [
|
||||||
|
true,
|
||||||
|
"single"
|
||||||
|
],
|
||||||
|
"radix": true,
|
||||||
|
"semicolon": [
|
||||||
|
true
|
||||||
|
],
|
||||||
|
"triple-equals": [
|
||||||
|
true,
|
||||||
|
"allow-null-check"
|
||||||
|
],
|
||||||
|
"typedef-whitespace": [
|
||||||
|
true,
|
||||||
|
{
|
||||||
|
"call-signature": "nospace",
|
||||||
|
"index-signature": "nospace",
|
||||||
|
"parameter": "nospace",
|
||||||
|
"property-declaration": "nospace",
|
||||||
|
"variable-declaration": "nospace"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"typeof-compare": true,
|
||||||
|
"unified-signatures": true,
|
||||||
|
"variable-name": false,
|
||||||
|
"whitespace": [
|
||||||
|
true,
|
||||||
|
"check-branch",
|
||||||
|
"check-decl",
|
||||||
|
"check-operator",
|
||||||
|
"check-separator",
|
||||||
|
"check-type"
|
||||||
|
],
|
||||||
|
"directive-selector": [
|
||||||
|
true,
|
||||||
|
"attribute",
|
||||||
|
"ngx",
|
||||||
|
"camelCase"
|
||||||
|
],
|
||||||
|
"component-selector": [
|
||||||
|
true,
|
||||||
|
"element",
|
||||||
|
"ngx",
|
||||||
|
"kebab-case"
|
||||||
|
],
|
||||||
|
"ban": [
|
||||||
|
true,
|
||||||
|
"eval",
|
||||||
|
"fit",
|
||||||
|
"fdescribe",
|
||||||
|
{
|
||||||
|
"name": "$",
|
||||||
|
"message": "please don't"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"use-input-property-decorator": true,
|
||||||
|
"use-output-property-decorator": true,
|
||||||
|
"no-output-rename": true,
|
||||||
|
"use-life-cycle-interface": true,
|
||||||
|
"use-pipe-transform-interface": true,
|
||||||
|
"component-class-suffix": true,
|
||||||
|
"directive-class-suffix": true,
|
||||||
|
"no-unused-variable": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user