Javascript 正在将文件上载到实时数据库中的firebase存储和索引-数据库中无条目

Javascript 正在将文件上载到实时数据库中的firebase存储和索引-数据库中无条目,javascript,firebase,ionic-framework,firebase-realtime-database,Javascript,Firebase,Ionic Framework,Firebase Realtime Database,我编写了一个函数,用于将本地文件(使用cordova文件)上载到firebase存储。看起来没有API来迭代存储中的所有文件(基于其他SO线程),所以我决定将下载位置写入实时数据库 目前,我的实时数据库和存储中的身份验证已关闭,无法进行测试。文件上传正确,我可以在我的存储中看到它,但我没有看到任何数据库条目。有人能帮忙解决问题吗 // upload trip data to firebase. currently a public bucket cloudUpload(prg) {

我编写了一个函数,用于将本地文件(使用cordova
文件
)上载到firebase存储。看起来没有API来迭代存储中的所有文件(基于其他SO线程),所以我决定将下载位置写入实时数据库

目前,我的实时数据库和存储中的身份验证已关闭,无法进行测试。文件上传正确,我可以在我的存储中看到它,但我没有看到任何数据库条目。有人能帮忙解决问题吗

 // upload trip data to firebase. currently a public bucket
  cloudUpload(prg) {
    console.log ("cloud upload");
    //this.presentLoader("loading...");
    let storageRef = firebase.storage().ref();
    console.log ("storage ref is "+storageRef);
    this.file.readAsArrayBuffer(this.file.dataDirectory, this.logFile)
    .then (succ=>{
      console.log ("File read");
      console.log (succ);
      let blob = new Blob([succ],{type:"text/plain"});
      console.log ("Blob  created");
      let name = "file-"+Date()+".txt";
      let uploadUrl = storageRef.child(`tripdata/${name}`);
      let uploadTask = uploadUrl.put(blob); 
      uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED,
        (snapshot) => {
          let progress = Math.round((snapshot.bytesTransferred / snapshot.totalBytes) * 100);
          prg.val = progress;

        },
        (error) => {
            console.log ("Firebase put error "+error);
            setTimeout(()=>{prg.val = -1; },500);
            this.presentToast("upload error","error") },
        () => { prg.val = 100;
                setTimeout(()=>{prg.val = -1; },500);
                // write download URL to realtime DB so we can iter it later
                // there is no API in storage today to iterate
                let  downloadURL = uploadTask.snapshot.downloadURL;
                console.log ("Download url is "+downloadURL);
                let key = 'tripDataIndex/'+name;
                console.log ("key="+key);
                 firebase.database().ref(key)
                .set ({'url':downloadURL, 'uploadedon':Date()}); // nothing created
                .catch (err=> {console.log ("ERROR "+err);this.presentToast("error creating index","error")})
                this.presentToast("upload complete")}
      )
    })
    .catch (err=>{console.log ("Cordova Read Error "+err);})
  }

问题似乎出在键值上。我的“名字”是

Date()


然而,非常奇怪的是,它没有抛出错误。我按照Frank的建议在末尾添加了一个
.catch
,但它从未进入catch处理程序。

您是否在交互式调试器中逐步完成了代码?你找到了应该将值写入数据库的代码了吗?是的,它到达了那里。我是否需要先将TripDataindex创建为列表?当您向它们写入值时,会在Firebase中创建键/路径,当您从中删除最后一个值时(相反)会将其删除。您确定您具有该位置的写入权限吗?控制台上是否显示任何信息?您可能还希望捕获以下描述的潜在问题:argh似乎问题出在键值中。我的“名字”是
let name=“file-”+Date()+“.txt”
--
Date()
包含空格/括号等--使用不同的键名非常有效!
let name = "file-"+Date()+".txt";