Skip to content

Example doesn't work with newest version: AngularFireUploadTask.downloadURL(); returns undefined #1645

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
takahser opened this issue May 14, 2018 · 7 comments

Comments

@takahser
Copy link

takahser commented May 14, 2018

Version info

Angular: "^5.2.1"
Firebase: "^5.0.2"
AngularFire: "5.0.0-rc.7"

It used to work on earlier versions, e.g.:
"angularfire2": "5.0.0-rc.6",
"firebase": "^5.0.2",

How to reproduce these conditions

See the example Monitoring upload percentage

@Component({
  selector: 'app-root',
  template: `
    <input type="file" (change)="uploadFile($event)" />
    <div>{{ uploadPercent | async }}</div>
    <a [href]="downloadURL | async">{{ downloadURL | async }}</a>
 `
})
export class AppComponent {
  uploadPercent: Observable<number>;
  downloadURL: Observable<string>;
  constructor(private storage: AngularFireStorage) {}
  uploadFile(event) {
    const file = event.target.files[0];
    const filePath = 'name-your-file-path-here';
    const task = this.storage.upload(filePath, file);
    
    // observe percentage changes
    this.uploadPercent = task.percentageChanges();
    // get notified when the download URL is available
    this.downloadURL = task.downloadURL();
  }
}

Expected behavior

On the current version, when uploading a file using AngularFireStorage.upload(filePath, file) the downloadUrl of the file can be requested by subscribing to AngularFireUploadTask.downloadURL():

AngularFireUploadTask.downloadURL().subscribe(console.log) // should log download url

Actual behavior

Instead of returning the URL, the subscription returns undefined:

AngularFireUploadTask.downloadURL().subscribe(console.log) // logs undefined

@jamesdaniels
Copy link
Member

Firebase 5.0 removed downloadUrl from upload task, so we did so too. I'll rework the doc.

@takahser
Copy link
Author

@jamesdaniels thanks for the info. Did they replace it with something else or can't we use this functionality anymore?

@jamesdaniels
Copy link
Member

jamesdaniels commented May 15, 2018 via email

@takahser
Copy link
Author

@jamesdaniels thanks for your advice, this is actually what I tried however, in my case I'm uploading a file and I'd like to get the download url as soon as the file is uploaded. Even if I wait with requesting the file after it was uploaded (I tried wait for the AngularFireStorage.upload to be fulfilled), we have race conditions, since at this time the firebase storage service won't necessarily have processed the new image and therefore I get a 404. The only way I was able to make it work in a "reliable" way was by using setTimeout which is obviously very ugly... Is there a better way to do this?

@jamesdaniels
Copy link
Member

@takahser see Jeff's comment #1649 (comment)

@jamesdaniels
Copy link
Member

Docs have been updated.

@Lx
Copy link

Lx commented Sep 11, 2018

The table in the updated docs still references getDownloadURL as an available method on AngularFireUploadTask, which doesn't seem to be the case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants