Skip to content

Instantly share code, notes, and snippets.

@aarivalagan
Created August 12, 2018 13:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aarivalagan/8bfbe47ef8cf0dac267374a8f0ef5b0f to your computer and use it in GitHub Desktop.
Save aarivalagan/8bfbe47ef8cf0dac267374a8f0ef5b0f to your computer and use it in GitHub Desktop.
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { AngularFireDatabase, AngularFireList } from 'angularfire2/database';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/catch';
import { catchError } from 'rxjs/operators';
@Injectable()
export class VDataService {
constructor(private db: AngularFireDatabase,
private http: HttpClient) { }
vList: AngularFireList<any>;
//url: string;
request_options: string;
getVideoData(): any {
this.vList = this.db.list('/newCour');
return this.vList;
}
UpdateVideoList($key: string, flag: boolean) {
this.vList.update($key, { Completed: flag });
}
uploadFile(file) {
let formData: FormData = new FormData();
formData.append('file', file, file.name);
this.http.post("http://localhost:/4200/", formData)
}
postFile(fileToUpload: File): Observable<boolean> {
const endpoint = 'your-destination-url';
const formData: FormData = new FormData();
formData.append('fileKey', fileToUpload, fileToUpload.name);
return this.http
.post(endpoint, formData, { headers: this.yourHeadersConfig })
.map(() => { return true; })
.catchError((e) => this.handleError(e));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment