【问题标题】:How to get the value of Firebase storage download url and store it in firebase storage....,如何获取 Firebase 存储下载 url 的值并将其存储在 Firebase 存储中......,
【发布时间】:2016-12-08 16:59:23
【问题描述】:

我想获取下载 url 的值并将其存储在 firebase 数据库中,

 var uploadTask = storageRef.child('video/' + file.name).put(file,metadata);

//检查上传进度

               uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED, // or 'state_changed'
              function(snapshot) {
                // Get task progress, including the number of bytes uploaded and the total number of bytes to be uploaded
                var progress = (snapshot.bytesTransferred / snapshot.totalBytes) * 100;
                console.log('Upload is ' + progress + '% done');
                switch (snapshot.state) {
                  case firebase.storage.TaskState.PAUSED: // or 'paused'
                    console.log('Upload is paused');
                    break;
                  case firebase.storage.TaskState.RUNNING: // or 'running'
                    console.log('Upload is running');
                    break;
                }
              }, function(error) {
              switch (error.code) {
                case 'storage/unauthorized':
                  // User doesn't have permission to access the object
                  break;

                case 'storage/canceled':
                  // User canceled the upload
                  break;
                case 'storage/unknown':
                  // Unknown error occurred, inspect error.serverResponse
                  break;
              }
            }, function() {

所以我想要的是获取 downloadURL 的值并存储它,但我不是 javascript 专家,所以我不知道如何获取它的变量值

      // Upload completed successfully, now we can get the download URL
      var downloadURL = uploadTask.snapshot.downloadURL;

      console.log(downloadURL);
    });

【问题讨论】:

    标签: javascript firebase firebase-realtime-database firebase-storage


    【解决方案1】:
    }, function()
     {
      // Upload completed successfully, now we can get the download URL
      var downloadURL = uploadTask.snapshot.downloadURL;
    
       var path = storageRef.fullPath
       var name = storageRef.name
        var imagesRef = storageRef.parent;
    
    
         var ctitle=video_title.value;
         var cdescription=video_description.value;
         var clength=video_length.value;
         var c_category=video_category.value;
    
         var created_at=video_created_at;
    
         var created_path=path;
    
         var created_name=name;
    
         var created_images_ref=imagesRef;
    
         var create_downloadURL=downloadURL;
    
    firebase.database().ref('Video').push({
    
    
        VTitle: ctitle,
        vDescription: cdescription,
        vLength: clength,
        VCategory: c_category,
    
        vCreatedAt: created_at,
    
        vcreated_path:created_path,
    
        vcreated_name:created_name,
    
        create_downloadURL:create_downloadURL,
    
    
    
        vcreated_images_ref:created_images_ref
        });
    
    
    
     // console.log(downloadURL);
    });
    

    【讨论】:

      【解决方案2】:

      之后 var uploadTask = storageRef.child('video/' + file.name).put(file,metadata);

      添加这些行

      var completed = function(data){ console.log(data.downloadURL); };
      
      uploadTask.then(completed, function(error){});
      

      我不能 100% 确定它会起作用,因为我还没有测试过。

      我已经获得了执行此操作的信息 Firebase Storage Documentation

      【讨论】:

      • 我想要的只是从另一个函数中获取该值,它有很多关于理解 javascript 函数和访问其他函数内部的数据......,
      猜你喜欢
      • 1970-01-01
      • 2020-09-23
      • 1970-01-01
      • 2019-11-07
      • 2018-12-08
      • 2018-07-04
      • 2018-08-09
      • 1970-01-01
      • 2021-08-22
      相关资源
      最近更新 更多