2016-12-07 97 views
0

我想下载URL的值,并将其存储在数据库火力,如何获得火力地堡存储下载URL的值,并将其存储在存储火力...,

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); 
    }); 

回答

0

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

+0

所有我想要的是从另一个函数获取价值得到了信息,以做到这一点,它有很多关于了解JavaScript函数和访问数据中的其他功能.. ...., –

+0

你有没有试过我的解决方案,看看它是否工作? – Lirianer

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); 
}); 
相关问题