【问题标题】:Google Storage: combine getName() and getDownloadURL()?谷歌存储:结合 getName() 和 getDownloadURL()?
【发布时间】:2020-11-03 01:38:24
【问题描述】:

通过以下代码,我收集了 Google Storage 中“文件夹”中的所有文件:

        // Get a reference to the storage service, which is used to create references in your storage bucket
        var storage = firebase.storage();

        // Create a storage reference from our storage service
        var storageRef = storage.ref();         
        
        // Create a reference under which you want to list
        var listRef = storageRef.child('folder');

        // Find all items
        listRef.listAll().then(function(result){
             result.items.forEach(function(itemRef){
                  itemRef.getDownloadURL().then(function(url){
                      
                        var item = $('<a>Download: ' + url + '</a>').attr({
                             'href': url
                        }).appendTo('#fileList').wrap('<li></li>');
                      
                  });
             })
        }).catch(function(error) {
            // Uh-oh, an error occurred!
            console.log('Uh-oh, an error occured: ' + error)
        });

到目前为止一切顺利。但是如何显示文件名而不是 url? getDownloadURL() 只返回我知道的 url...

【问题讨论】:

    标签: javascript google-cloud-storage firebase-storage


    【解决方案1】:

    您的itemRefReference 类型的对象。根据链接的 API 文档,您可以使用其fullPath 属性获取对象的完整路径,或使用name 获取尾随文件名。

    【讨论】:

    猜你喜欢
    • 2020-07-02
    • 2019-02-23
    • 1970-01-01
    • 2019-11-06
    • 1970-01-01
    • 1970-01-01
    • 2021-04-06
    • 1970-01-01
    • 2014-07-20
    相关资源
    最近更新 更多