我正在向 Azure 事件中心發送一個 json 物件(在 python 中),該物件通過事件中心的事件捕獲功能路由到 Blob 存盤。該檔案存盤在 Apache AVRO 中。當我在在線 AVRO 閱讀器上上傳檔案時,我看到類似這樣的內容 .. AVRO Reader Snip
實際資料在影像的主體中。我不希望 Azure 事件中心將我的資料編碼為 base64。我應該對下面的代碼進行哪些更改。
producer = EventHubProducerClient.from_connection_string(conn_str=EVENTHUB_CONNECTION_STR, eventhub_name=eventhub)
async with producer:
dictionary_obj = {}
dictionary_obj['id'] = 1
dictionary_obj['Name'] = 'Alex'
dictionary_obj['Attr1'] = 1
MESSAGE = json.dumps(dictionary_obj)
event_data_batch = await producer.create_batch()
event_data_batch.add(EventData(MESSAGE))
await producer.send_batch(event_data_batch)
await producer.close()
uj5u.com熱心網友回復:
Azure 事件中心將訊息正文中的資料作為不透明位元組陣列處理。它從不在 avro 寫入之前對其進行編碼。
uj5u.com熱心網友回復:
我們可以使用 python 腳本來解碼內容。下面是示例 python 腳本。
import base64
image = open('deer.gif', 'rb')
image_read = image.read()
image_64_encode = base64.encodestring(image_read)
image_64_decode = base64.decodestring(image_64_encode)
image_result = open('deer_decode.gif', 'wb') # create a writable image and write the decoding result
image_result.write(image_64_decode)
請參閱此博客以了解有關此內容的更多資訊。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/408504.html
標籤:
