【问题标题】:Flask - Firebase Storage - Image uploadFlask - Firebase 存储 - 图片上传
【发布时间】:2020-12-30 16:10:30
【问题描述】:

我试图允许用户以这种方式将图像上传到我的 firebase 存储数据库:

import pyrebase
from flask import *
app = Flask(__name__)

config = {
    #Hidden
}

firebase = pyrebase.initialize_app(config)
storage = firebase.storage()
auth = firebase.auth()

@app.route('/', methods=['GET', 'POST'])
#Login
def basic():
    unsuccessful = 'Please check your credentials'
    successful = 'Login successful'
    if request.method == 'POST':
        email = request.form['name']
        password = request.form['pass']
        try:
            auth.sign_in_with_email_and_password(email, password)
            return render_template('index.html', s=successful)
        except:
            return render_template('new.html', us=unsuccessful)
    return render_template('new.html')

#Posting function
@app.route('/', methods=['GET','POST'])
def newProduct():
    if request.method == 'POST':
        try:
            path_on_cloud = "images/newproduct.jpg"
            path_local=request.form['file']
            storage.child(path_on_cloud).put(path_local)
            return render_template("index.html")
        except:
            return render_template("index.html")

允许用户登录的基本功能没有任何问题。 但是,在尝试将图片上传到 Firebase 存储数据库时出现以下 404 错误: “未找到 在服务器上找不到请求的 URL。如果您手动输入了 URL,请检查您的拼写并重试。”

我有两个 html 文件:new.html 包含登录信息,index.html 是完成图片上传的页面。

我希望你们中的一个人能看到我做错了什么或我错过了什么。 提前致谢!

【问题讨论】:

  • 这两个函数的路径相同。对吗?

标签: python firebase flask firebase-storage pyrebase


【解决方案1】:

从您共享的代码中,两个页面都有相同的@app.route。每个人都应该有自己的@app.route。

发帖功能应该是:

@app.route('/newProduct', methods=['GET','POST'])

【讨论】:

猜你喜欢
  • 2020-10-05
  • 2021-06-28
  • 2021-12-23
  • 1970-01-01
  • 2021-08-18
  • 2019-12-04
  • 1970-01-01
  • 2016-12-24
相关资源
最近更新 更多