getDownloadURL无法正常工作-Firebase存储(Web)
getDownloadURL does not work correctly - Firebase Storage (Web)
下面的代码似乎没有记录正在上传的文件的下载URL,并给了我以下错误。
获取。。。{不是下载URL的URL}。。。404()
这是我的密码。
//Get image
var file = a.target.files[0];
//create a storage reference
var storageRef = firebase.storage().ref('images/' + file.name);
//store the image
var task = storageRef.put(file);
var storage = firebase.storage();
storageRef.child('images/'+file.name).getDownloadURL().then(function(url) {
console.log(url);
}).catch(function(error) {
// Handle any errors
});
那么我该如何获得下载URL呢?
从上传文件到Firebase Storage的文档中可以看到以下示例:
// File or Blob, assume the file is called rivers.jpg
var file = ...
// Upload the file to the path 'images/rivers.jpg'
// We can use the 'name' property on the File API to get our file name
var uploadTask = storageRef.child('images/' + file.name).put(file);
// Register three observers:
// 1. 'state_changed' observer, called any time the state changes
// 2. Error observer, called on failure
// 3. Completion observer, called on successful completion
uploadTask.on('state_changed', function(snapshot){
// Observe state change events such as progress, pause, and resume
// See below for more detail
}, function(error) {
// Handle unsuccessful uploads
}, function() {
// Handle successful uploads on complete
// For instance, get the download URL: https://firebasestorage.googleapis.com/...
var downloadURL = uploadTask.snapshot.downloadURL;
});
您可以看到,此示例在上传完成后获得下载URL。
如果你不关心进展和失败,它可以简单到:
uploadTask.on('state_changed', null, null, function() {
var downloadURL = uploadTask.snapshot.downloadURL;
});
相关文章:
- 在firebase(web)上存储数据时出现问题
- 将Firebase url存储在外部属性文件中
- 在Firebase中存储ID列表
- 将数据作为 JSON 对象存储在 Firebase 中
- 使用 Firebase 存储数据以生成 xml
- 将文件存储在Firebase存储中
- 当我将图像上传到firebase存储并检索下载url并在img标记中显示时,但它显示多次
- Firebase存储getDownloadURL()不返回工作url
- firebase存储中的更新记录只有在刷新页面后才可见
- 使用Firebase存储数组
- Firebase存储静默失败
- 用JavaScript从Firebase存储中重命名或下载文件
- 如何在firebase存储中引用映像
- Angular 2 Firebase存储-上传完成后预览图像
- getDownloadURL无法正常工作-Firebase存储(Web)
- 无法将图像上载到Firebase存储
- 函数,该函数从Firebase存储返回下载URL
- Firebase存储-某些下载URL为空
- 将图片从 React-Native 应用上传到 Firebase 存储
- 如何将一组图片上传到 Firebase 存储