簡體   English   中英

如何在 Blob 觸發器中使用 Python 打開 Blob 觸發文件 Azure Function

[英]How to open a blob triggered file using Python in an blob trigger Azure Function

我正在嘗試使用 PyPDF2 從 blob 觸發的 PDF 文件中提取文本。 但是,我收到“UnsupportedOperation:seek”錯誤。

這是我的代碼:

import logging

import azure.functions as func

from io import StringIO

import re

import os

import PyPDF2

def main(myblob: func.InputStream,blobout: func.Out[str],context: func.Context):
logging.info(f"--- Python blob trigger function processed blob \n"
             f"----- Name: {myblob.name}\n"
             f"----- Blob Size: {myblob.length} bytes")


pdfblob = PyPDF2.PdfFileReader(myblob)

這是錯誤:

System.Private.CoreLib:執行 function 時出現異常:Functions.Assessment。 System.Private.CoreLib:結果:失敗異常:UnsupportedOperation:seek

我對 azure 功能比較陌生,非常感謝您的幫助。

謝謝你。

我用 blob 輸入進行測試,它可以被復制。 下面是我的解決方案,創建一個BytesIO stream 並存儲 blob 輸入流。

    blob_bytes = inputblob.read()
    blob_to_read = BytesIO(blob_bytes)
    fileReader = PyPDF2.PdfFileReader(blob_to_read)

    logging.info(fileReader.numPages) 

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM