1

Im trying to allow users to upload images to my firebase storage database this way:

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")

The basic function which allows the users to log in works without any issues. However i get the following 404 error when trying to upload a picture to the firebase storage database: "Not Found The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again."

i have two html files: new.html which contains the log in, and index.html which is the page that follows where the upload of an image is done.

I hope one of you can see what i've done wrong or what im missing. Thanks in advance!

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Ronnie
  • 53
  • 1
  • 4

1 Answers1

2

From the code that you shared, you have the same @app.route for both pages. Each one should have their own @app.route.

Posting function should be:

@app.route('/newProduct', methods=['GET','POST'])
thejdah
  • 335
  • 2
  • 3
  • 17
  • https://flask.palletsprojects.com/en/1.1.x/tutorial/views/ Flask documentation for blueprints and views. – thejdah Sep 12 '20 at 16:21