Warning: file_put_contents(/datas/wwwroot/jiajiahui/core/caches/caches_template/2/default/show.php): failed to open stream: Permission denied in /datas/wwwroot/jiajiahui/core/libraries/classes/template_cache.class.php on line 55

Warning: chmod(): Operation not permitted in /datas/wwwroot/jiajiahui/core/libraries/classes/template_cache.class.php on line 56
如何使用JavaScript将多个文件上传到Firebase存储引用? - 源码之家

如何使用JavaScript将多个文件上传到Firebase存储引用?

问题描述:

Firebase存储的Put方法似乎一次只能处理一个文件。我如何得到这个与多个文件一起工作?我试图等待每个上传完成并为每个上传收集一个下载url,然后继续并将这些url保存在实时数据库中节点的数组中,但似乎无法找到处理此问题的最佳方法。如何使用JavaScript将多个文件上传到Firebase存储引用?

+0

你可以叫'把()'为每个文件,您要上传。如果您在完成此项工作时遇到问题,请分享[重现您卡住的最小代码](http://*.com/help/mcve)。 –

我写的这个GitHub gist

// set it up 
firebase.storage().ref().constructor.prototype.putFiles = function(files) { 
    var ref = this; 
    return Promise.all(files.map(function(file) { 
    return ref.child(file.name).put(file); 
    })); 
} 

// use it! 
firebase.storage().ref().putFiles(files).then(function(metadatas) { 
    // Get an array of file metadata 
}).catch(function(error) { 
    // If any task fails, handle this 
});