import b2sdk.v2 as b2 #Backblaze img2img upload bucket import os from dotenv import load_dotenv load_dotenv() info = b2.InMemoryAccountInfo() b2_api = b2.B2Api(info) application_key_id = os.getenv("BB_KeyID") application_key = os.getenv("BB_AppKey") #print(application_key_id,application_key) b2_api.authorize_account("production", application_key_id, application_key) BB_bucket_name=os.getenv("BB_bucket") BB_bucket=b2_api.get_bucket_by_name(os.getenv("BB_bucket")) BB_defurl=os.getenv("BB_defurl") def BB_uploadfile(local_file,file_name,FRIENDLY_URL=True): metadata = {"key": "value"} uploaded_file = BB_bucket.upload_local_file( local_file=local_file, file_name=file_name, file_infos=metadata, ) img_url=b2_api.get_download_url_for_fileid(uploaded_file.id_) if FRIENDLY_URL: #Get friendly URP img_url=BB_defurl+"/file/"+BB_bucket_name+"/"+file_name print("backblaze", img_url) return img_url