简体   繁体   English

Flask Python Firebase存储

[英]Flask Python Firebase storage

I'm trying to upload an image to Firebase. 我正在尝试将图像上传到Firebase。

storage = firebase.storage()
storage.child("images/example.jpg").put("cat.jpg")

I can't seem to allow user to browse an image file from their PC and upload it to Firebase. 我似乎无法允许用户从其PC浏览图像文件并将其上传到Firebase。 How should I go about doing this? 我应该怎么做呢? Please kindly guide me in the right direction ,thank you! 请朝正确的方向引导我,谢谢!

Use <input type="file".. to trigger the select window and may be listen the onChange="handleUpload()" event to handle your firebase upload. 使用<input type="file"..来触发选择窗口,并且可以监听onChange="handleUpload()"事件来处理您的Firebase上传。

function handleUpload(event) {
    // Use this event to get the input element
    const files = event.target.files;
    if (!files.length) {
      return alert('Please choose a file to upload first.');
    }

    // Always multiple files get the first file if no `multiple` in input
    var file = files[0];
    var fileName = file.name;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM