var selectedfile;
function upload()
{
selectedfile= document.getElementById("file");
var filename=selectedfile.files.item(0).name;
var storageRef=firebase.storage().ref('/Images/'+filename);
var uploadTask=storageRef.put(selectedfile);
uploadTask.on('state_changed',function(snapshot){},function(errors){},
function(){
var downloadUrl=uploadTask.snapshot.downloadUrl;
console.log(downloadUrl);
});
}
<input type="file" name="fileid" id="file">
<button onclick="upload();" id="selbt">Upload</button>
当我尝试将图片上传到我的Firebase存储空间时,它会抛出一些未被捕获的异常,例如:
答案 0 :(得分:0)
<form method="post" enctype="multipart/form-data">
<div>
<label for="file">Choose file to upload</label>
<input type="file" id="file" name="file" multiple>
</div>
<div>
<button>Submit</button>
</div>
</form>
答案 1 :(得分:0)
尝试
var filename=selectedfile.files[0].name;