+ removeTag(tag: string) {
+ this.video.tags.splice(this.video.tags.indexOf(tag), 1);
+ }
+
+ upload() {
+ const item = this.uploader.queue[0];
+ // TODO: wait for https://github.com/valor-software/ng2-file-upload/pull/242
+ item.alias = 'videofile';
+
+ item.onSuccess = () => {
+ console.log('Video uploaded.');
+
+ // Print all the videos once it's finished
+ this.router.navigate(['/videos/list']);
+ };
+
+ item.onError = (response: string, status: number) => {
+ // We need to handle manually these cases beceause we use the FileUpload component
+ if (status === 400) {
+ this.error = response;
+ } else if (status === 401) {
+ this.error = 'Access token was expired, refreshing token...';
+ this.authService.refreshAccessToken().subscribe(
+ () => {
+ // Update the uploader request header
+ this.uploader.authToken = this.authService.getRequestHeaderValue();
+ this.error += ' access token refreshed. Please retry your request.';
+ }
+ );
+ } else {
+ this.error = 'Unknow error';
+ console.error(this.error);
+ }
+ };
+
+
+ this.uploader.uploadAll();