简体   繁体   中英

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

I am trying to extract text from a blob triggered PDF file using PyPDF2. However, I am receiving an error of "UnsupportedOperation: seek".

This is my code:

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)

This is the error:

System.Private.CoreLib: Exception while executing function: Functions.Assessment. System.Private.CoreLib: Result: Failure Exception: UnsupportedOperation: seek

I am relatively new to azure functions and would really appreciate the help.

Thank you.

I test with blob input and it could be reproduced. The below is my solution, create a BytesIO stream and store the blob inputstream.

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

    logging.info(fileReader.numPages) 

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM