Answer the question
In order to leave comments, you need to log in
How to either save a file from a directory to the database, or specify a link in the image database?
import telebot
import mysql.connector
from telebot import types, TeleBot
from telebot.types import Message
import os
directory = "45468798"
parent_dir = "C:/Users/1/PycharmProjects/photo/"
path = os.path.join(parent_dir, directory)
os.mkdir(path)
print("Directory '%s' created" % directory)
@bot.message_handler(content_type=['photo'])
def process_photo_step(message):
chat_id = message.from_user.id
file_info = bot.get_file(message.photo[len(message.photo) - 1].file_id)
downloaded_file = bot.download_file(file_info.file_path)
src = r"{}\{}\{}".format(os.getcwd(), chat_id, message.photo[-1].file_id)
with open(src, 'wb') as new_file:
new_file.write(downloaded_file)
msg = bot.send_message(message.chat.id, "спасибо")
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question