文件未上传到数据库,下载URL未显示

时间:2020-02-07 18:25:23

标签: javascript html firebase firebase-storage

文件未上传且下载网址未显示

q

当我运行此代码时,控制台会显示** storageRef未定义**

当我将storageRef声明为 <script> var file = document.getElementById('file'); // Create the file metadata var metadata = { contentType: 'image/jpeg' }; // Upload file and metadata to the object 'images/mountains.jpg' var uploadTask = storageRef.child('images/' + file.name).put(file, metadata); // Listen for state changes, errors, and completion of the upload. 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) { // A full list of error codes is available at // https://firebase.google.com/docs/storage/web/handle-errors 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() { // Upload completed successfully, now we can get the download URL uploadTask.snapshot.ref.getDownloadURL().then(function(downloadURL) { console.log('File available at', downloadURL); }); }); </script> 之类的变量时,它说无法读取子级的属性

我想从此代码中上传文档并显示下载URL

0 个答案:

没有答案