Skip to content

Instantly share code, notes, and snippets.

@dajor dajor/
Last active Oct 22, 2019

What would you like to do?
Read a png or jpg from an Azure Blog Storage and decode the barcode and upload the document to SugarCRM
# Last Tested Version 1.8.1
import logging
import azure.functions as func
from import BlockBlobService
import os, io
import json
import base64
from pyzbar.pyzbar import decode
from PIL import Image
from sugarcrm.client import Client
import base64
SugarURL = os.environ['SugarURL']
SugarUser = os.environ['SugarUser']
SugarPassword = os.environ['SugarPassword']
def main(myblob: func.InputStream):"Python blob trigger function processed blob \n"
f"Name: {}\n"
f"Blob Size: {myblob.length} bytes")
file =
image = io.BytesIO(file)
for obj in barcode:
client = Client(SugarURL, SugarUser, SugarPassword)
item = {'Name': }
Note = client.set_entry('Notes', item)
Debitor = client.search_by_module(, ['DEB_Debitoren'])
relation = client.set_relationship('DEB_Debitoren', Debitor['entry_list'][0]['records'][0]['id']['value'],'deb_debitoren_notes_1', [Note['id']])
print ("Cloud not find")
image = io.BytesIO(file)
encoded_string = base64.b64encode(image.getvalue())
encoded_string = encoded_string.decode()"Upload \n"
# f"Name: {}\n"
# f"Base64: {encoded_string}")
client.set_note_attachment(Note['id'],, encoded_string)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.