Skip to content
This repository was archived by the owner on Aug 16, 2022. It is now read-only.

Commit 223f012

Browse files
add: storage
1 parent cd1bb34 commit 223f012

10 files changed

+116
-13
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1-
<p>
2-
delete-file works!
3-
</p>
1+
<div id="wrapper">
2+
<div>
3+
<h2>Delete file</h2>
4+
<div class="divider">
5+
<mat-divider></mat-divider>
6+
</div>
7+
8+
<div id="content">
9+
<div>
10+
</div>
11+
12+
</div>
13+
</div>
14+
</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#wrapper {
2+
3+
margin-bottom: 7vh;
4+
margin-top: -10px;
5+
6+
.divider {
7+
width: 80%;
8+
margin-bottom: 3vh;
9+
}
10+
11+
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1-
<p>
2-
download-file works!
3-
</p>
1+
<div id="wrapper">
2+
<div>
3+
<h2>Download file</h2>
4+
<div class="divider">
5+
<mat-divider></mat-divider>
6+
</div>
7+
8+
<div id="content">
9+
<div>
10+
</div>
11+
12+
</div>
13+
</div>
14+
</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#wrapper {
2+
3+
margin-bottom: 7vh;
4+
margin-top: -10px;
5+
6+
.divider {
7+
width: 80%;
8+
margin-bottom: 3vh;
9+
}
10+
11+
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1-
<p>
2-
upload-file works!
3-
</p>
1+
<div id="wrapper">
2+
<div>
3+
<h2>Upload file</h2>
4+
<div class="divider">
5+
<mat-divider></mat-divider>
6+
</div>
7+
8+
<div id="content">
9+
<div>
10+
<input type="file" (change)="onChange($event)">
11+
<button mat-raised-button (click)="upload()" disabled>UPLOAD</button>
12+
</div>
13+
14+
</div>
15+
</div>
16+
</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#wrapper {
2+
3+
margin-bottom: 7vh;
4+
margin-top: -10px;
5+
6+
.divider {
7+
width: 80%;
8+
margin-bottom: 3vh;
9+
}
10+
11+
}
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,27 @@
11
import { Component, OnInit } from '@angular/core';
22

3+
import { StorageService } from '../../storage.service';
4+
35
@Component({
46
selector: 'app-upload-file',
57
templateUrl: './upload-file.component.html',
68
styleUrls: ['./upload-file.component.scss']
79
})
810
export class UploadFileComponent implements OnInit {
911

10-
constructor() { }
12+
file: File;
13+
14+
constructor(private storage: StorageService) { }
1115

1216
ngOnInit() {
1317
}
1418

19+
onChange(event: Event) {
20+
this.file = event.target['files'][0];
21+
}
22+
23+
upload() {
24+
this.storage.uploadFile(this.file);
25+
}
26+
1527
}

src/app/storage/storage.md

Whitespace-only changes.

src/app/storage/storage.module.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ import { NgModule } from '@angular/core';
22
import { CommonModule } from '@angular/common';
33
import { StorageRoutingModule } from './storage-routing.module';
44
import {
5-
MatCardModule
5+
MatCardModule,
6+
MatDividerModule,
7+
MatButtonModule,
8+
MatIconModule,
69
} from '@angular/material';
710

811
import { StorageComponent } from './component/storage.component';
@@ -16,7 +19,10 @@ import { StorageService } from './storage.service';
1619
imports: [
1720
CommonModule,
1821
StorageRoutingModule,
19-
MatCardModule
22+
MatCardModule,
23+
MatDividerModule,
24+
MatButtonModule,
25+
MatIconModule,
2026
],
2127
declarations: [
2228
StorageComponent,

src/app/storage/storage.service.ts

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,26 @@
11
import { Injectable } from '@angular/core';
2+
import {
3+
AngularFireStorage,
4+
AngularFireUploadTask
5+
} from 'angularfire2/storage';
26

37
@Injectable({
48
providedIn: 'root'
59
})
610
export class StorageService {
711

8-
constructor() { }
12+
constructor(private storage: AngularFireStorage) { }
13+
14+
uploadFile(file: File) {
15+
this.storage.ref(file.name).put(file);
16+
}
17+
18+
deleteFile(file: File) {
19+
this.storage.ref(file.name).delete();
20+
}
21+
22+
getDownloadURL(file: File) {
23+
return this.storage.ref(file.name).getDownloadURL();
24+
}
25+
926
}

0 commit comments

Comments
 (0)