How to increment a variable in the middle of an sql query in Flask?

Asked

Viewed 13 times

0

Hello, I’ve been trying for a while to receive and insert an image that needs to be BLOB type in Mariadb bank with Flask. However, when I try to insert the image into the bank with flask I get the error:

Error: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'b'\x89PNG\r\n\x1a\n\

My code:

@app.route('/api/images', methods=['POST'])
def index():
print('request.data: ', request.data)
if request.data:
    image = request.data
    try:

        # conexão com MariaDB
        connection = mariadb.connect(**config)
        
        # criando um cursor de conexão
        cur = connection.cursor()
        
        # executando a query sql
        cur.execute(f"INSERT INTO images (image) VALUES({image})")
        connection.commit()

        connection.close()
        
        return 'Sucessoooo!'
      
    except mariadb.Error as e:
        print(f"Error: {e}")

        return f"Error: {e}"

app.run()

esse é o envio do front

Someone can help me?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.