So, I want to be able to upload a photo I have generated with the qrcode class to Telegram through telepot. This is the code I have originally tried!
img = qrcode.make(totp.provisioning_uri(settings.OTPNAME)) # This creates the raw image (of the qr code)
output = BytesIO() # This is a "file" written into memory
img.save(output, format="PNG") # This is saving the raw image (of the qr code) into the "file" in memory
bot.sendPhoto(uid, output) # This is sending the image file (in memory) to telegram!
If I was going to accept the solution of saving the photo to the hard drive and then uploading it, I could upload it using this code!
imgTwo = open("image.png", 'rb') # So this works when combined with bot.sendPhoto(uid, imgTwo) # 'rb' means read + binary
bot.sendPhoto(uid, imgTwo)
I have tried wrapping the BytesIO image in a BufferedReader and even giving it a fake name.
#output2 = BufferedReader(output)
#output.name = "fake.png"
#bot.sendPhoto(uid, ("fake.png", output))
I have spent the past few days trying to figure out why I cannot upload the photo from memory. I have looked through various solutions such as the fake name solution!
The error Telegram keeps giving me is the file must not be empty. Saving it to the hard drive shows that it isn't empty and scanning the qrcode with my authentication app shows the qr code is not corrupted! Thanks!
telepot.exception.TelegramError: ('Bad Request: file must be non-empty', 400, {'error_code': 400, 'ok': False, 'description': 'Bad Request: file must be non-empty'})