import { Component, OnInit } from '@angular/core';
import { AngularFireStorage, AngularFireUploadTask, AngularFireStorageReference } from 'angularfire2/storage';
import { Observable } from 'rxjs';
@Component({
selector: 'app-file-upload',
templateUrl: './file-upload.component.html',
styleUrls: ['./file-upload.component.css']
})
export class FileUploadComponent implements OnInit {
task: AngularFireUploadTask;
// Progress monitoring
percentage: Observable<number>;
snapshot: Observable<any>;
// Download URL
downloadURL: Observable<string>;
// State for dropzone CSS toggling
isHovering: boolean;
constructor(private storage: AngularFireStorage) { }
ngOnInit() {
}
toggleHover(event: boolean) {
this.isHovering = event;
}
startUpload(event: FileList) {
// The File object
const file = event.item(0)
// Client-side validation example
// if (file.type.split('/')[0] !== 'image') {
// console.error('unsupported file type :( ')
// return;
// }
// The storage path
const path = `test/${new Date().getTime()}_${file.name}`;
const ref = this.storage.ref(path);
// Totally optional metadata
// The main task
this.task = this.storage.upload(path, file);
// Progress monitoring
this.percentage = this.task.percentageChanges();
this.snapshot = this.task.snapshotChanges()
// The file's download URL
}
我正在使用Angular6和Firebase存储,并且希望检索我上传到存储的文件的下载URL。我已经尝试过:
this.downloadURL = ref.getDownloadURL()
但是我没有得到网址。
如果我评论以上语句,项目将编译并运行,甚至文件也已上载到Firebase存储中,但是,我一直在控制台中收到此错误:
HTTP404: NOT FOUND - The server has not found anything matching the requested URI (Uniform Resource Identifier).
(XHR)GET - https://firebasestorage.googleapis.com/v0/b/testfirestore1-b8d7b.appspot.com/o/test%2F1551208510383_testup2.txt
我的问题的解决方法是什么?