You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/storage/storage.md
+68-11
Original file line number
Diff line number
Diff line change
@@ -45,13 +45,62 @@ export class AppComponent {
45
45
46
46
### Uploading blobs
47
47
48
-
There are two options for uploading files.
48
+
There are three options for uploading files.
49
49
50
50
51
-
| method ||
52
-
| ---------|--------------------|
53
-
|`put(data: Blob, metadata?: storage.UploadMetadata): AngularFireUploadTask`| Starts the upload of the blob to the storage reference's path. Returns an `AngularFireUploadTask` for upload monitoring. |
51
+
| method ||
52
+
| ---------|--------------------|
53
+
|`put(data: Blob, metadata?: storage.UploadMetadata): AngularFireUploadTask`| Starts the upload of the blob to the storage reference's path. Returns an `AngularFireUploadTask` for upload monitoring. |
54
54
|`putString(data: string, format?: StringFormat, metadata?: UploadMetadata): AngularFireUploadTask`| Updates an existing item in the array. Accepts a key, database reference, or an unwrapped snapshot. |
55
+
|`upload(path: string, data: StringFormat, metadata?: UploadMetadata): AngularFireUploadTask`| Upload or update a new file to the storage reference's path. Returns an `AngularFireUploadTask` for upload monitoring. |
An `AngularFireUploadTask` has methods for observing upload percentage as well as the final download URL.
79
128
80
-
| method ||
81
-
| ---------|--------------------|
82
-
|`snapshotChanges(): Observable<FirebaseStorage.UploadTaskSnapshot>`| Emits the raw `UploadTaskSnapshot` as the file upload progresses. |
83
-
|`percentageChanges(): Observable<number>`| Emits the upload completion percentage. |
84
-
|`downloadURL(): Observable<string>`| Emits the download url when available |
129
+
| method ||
130
+
| ---------|--------------------|
131
+
|`snapshotChanges(): Observable<FirebaseStorage.UploadTaskSnapshot>`| Emits the raw `UploadTaskSnapshot` as the file upload progresses. |
132
+
|`percentageChanges(): Observable<number>`| Emits the upload completion percentage. |
133
+
|`getDownloadURL(): Observable<any>`| Emits the download url when available |
85
134
86
135
#### Example Usage
87
136
137
+
The method `getDownloadURL()` doesn't rely on the task anymore, hence, in order to get the url we should use the finalize method from RxJS on top of the storage ref.
138
+
88
139
```ts
140
+
import { finalize } from'rxjs/operators';
141
+
89
142
@Component({
90
143
selector: 'app-root',
91
144
template: `
@@ -101,12 +154,16 @@ export class AppComponent {
101
154
uploadFile(event) {
102
155
const file =event.target.files[0];
103
156
const filePath ='name-your-file-path-here';
157
+
const fileRef =this.storage.ref(filePath);
104
158
const task =this.storage.upload(filePath, file);
105
-
159
+
106
160
// observe percentage changes
107
161
this.uploadPercent=task.percentageChanges();
108
162
// get notified when the download URL is available
0 commit comments