Converting Media(jpg, mp4...) into Base64 data, insert into database, and displaying onto html page

Published: 16 April 2021
on channel: ZeroLife
162
2

//Python Part//
import base64, sqlite3

def convertToBinaryThenBase64(filename='c:/home/pic.png'):
with open(filename, 'rb') as fout:
blobData = fout.read()
base64_data = base64.b64encode(blobData)
return base64_data

def db_give(db_name='c:/home/mybase.db', table='mytable', data=''):
data_val = convertToBinaryThenBase64('C:/home/pic.png')
statement = 'INSERT INTO mytable(pic BLOB NOT NULL) VALUES(?)'
conn = sqlite3.connect(db_name)
cursor = conn.cursor()
with conn:
cursor.execute(statement, data_val)

link = 'data:image/png;base64,'+base64_data.decode()

//HTML Part//
img src="{{link}}"

What it really looks like:
img src="data:image/png;base64,343,3424,34234,,2342,,345,434.."

PAT:   / rezatahirkheli  
PP: https://www.paypal.com/paypalme/rezat...
BTC: 3EUQBWZKX9Vcwdffd3cUGATQopxrAQQxJ9
LTC: MBXE6hJgxxFYSD8SjmR7sHCHGTqFXmNGoU
GFM: https://gofund.me/7d6500bd


Watch video Converting Media(jpg, mp4...) into Base64 data, insert into database, and displaying onto html page online without registration, duration hours minute second in high quality. This video was added by user ZeroLife 16 April 2021, don't forget to share it with your friends and acquaintances, it has been viewed on our site 162 once and liked it 2 people.