gpt4 book ai didi

javascript - uploadTask.snapshot.downloadURL 未在响应中给出文件的下载 URL

转载 作者:行者123 更新时间:2023-12-03 00:07:48 25 4
gpt4 key购买 nike

我目前正在开发一个 Angular 类(class),但在将文件上传到 Firebase 时遇到问题,我可以上传文件,但没有得到下载 URL 的响应:

import { Injectable } from '@angular/core';
import { AngularFireDatabase, AngularFireList,
AngularFireObject } from 'angularfire2/database';
import * as firebase from 'firebase';
import { Archivo } from '../uploads/file.modal';
@Injectable({
providedIn: 'root'
})
export class LoadfileService {

private basePath: string = '/uploads';
uploads: AngularFireList<Archivo[]>;

constructor( public angularFireDatabase: AngularFireDatabase) { }

pushUpload(upload: Archivo) {
const storageRef = firebase.storage().ref();
const uploadTask = storageRef.child(`${this.basePath}/${upload.file.name}`).put(upload.file);

uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED,
(snapshot) =>{
upload.progress = (uploadTask.snapshot.bytesTransferred / uploadTask.snapshot.totalBytes * 100);
},
(error) => {
console.log(error);
},
() => {
// tslint:disable-next-line: deprecation
upload.url = uploadTask.snapshot.downloadURL;
upload.name = upload.file.name;
this.saveFileData(upload);
});
}

private saveFileData(upload: Archivo) {
this.angularFireDatabase.list(`${this.basePath}/`).push(upload);
}
}

这是我在上传服务中使用的代码,它告诉我 donwloadURL 已被弃用。

我正在寻找 atm 解决方案,但没有找到任何有用的东西。

最佳答案

谷歌搜索一段时间后问题解决了:

      pushUpload(upload: Archivo) {
const storageRef = firebase.storage().ref();
const uploadTask = storageRef.child(`${this.basePath}/${upload.file.name}`).put(upload.file);

storageRef.child(`${this.basePath}/${upload.file.name}`).getDownloadURL().then(ref => {
this.urlDownload = ref;
});

uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED,
(snapshot) =>{
upload.progress = (uploadTask.snapshot.bytesTransferred / uploadTask.snapshot.totalBytes * 100);
},
(error) => {
console.log(error);
},
() => {
upload.url = this.urlDownload;
upload.name = upload.file.name;
this.saveFileData(upload);
});
}

关于javascript - uploadTask.snapshot.downloadURL 未在响应中给出文件的下载 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54884401/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com