To archive this, you have to have VSCode installed in local machine.
Step 1: Install Azurite in VSCode
- Open VSCode
Extensions
and searchAzurite
, install it. - Press
F1
, in command bar, searchAzurite: Start
, select it then the Azurite will start in your local machine.
Step 2: Install Microsoft Azure Storage Explorer
- Download Azure Storage Explorer.
- Install and Open it.
- Under
Emulator & Attached
->Storage Accounts
->(Emulator - Default Port) (Key)
->Blob Containers
, create a new container for testing.
Step3: Change local.settings.json
Change AzureWebJobsStorage
value to UseDevelopmentStorage=true
. As following:
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "python",
"AzureWebJobsFeatureFlags": "EnableWorkerIndexing"
}
}
Step 4: start up
Here is my code:
import azure.functions as func
import logging
app = func.FunctionApp()
@app.blob_trigger(arg_name="inputblob", path="input_container/{name}.pdf", connection="AzureWebJobsStorage")
@app.blob_output(arg_name="outputblob", path="output_container/{filename}.pdf.json", connection="AzureWebJobsStorage")
def blob_trigger(inputblob: func.InputStream, outputblob: func.Out[str]):
logging.info(f"Python blob trigger function processed blob "
f"Name: {inputblob.name} "
f"Blob Size: {inputblob.length} bytes")
outputblob.set(inputblob)
Step 5: Run
func start
Open Azure Storage Explorer and upload file. You will see the log in terminal.
Please remind the the
arg_name
can only be English letters and numbers, and NO underscore_
and other special charactars.