-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunction_app.py
37 lines (34 loc) · 1.53 KB
/
function_app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import azure.functions as func
import json
import logging
from azure.storage.blob import BlobServiceClient as bsc
app = func.FunctionApp()
@app.function_name("BlobTrigger1")
@app.blob_trigger("myblob", "source/{name}", connection="connString")
def test_function(myblob: func.InputStream):
logging.info("Python blob trigger function processed blob\n"
f"Name: {myblob.name}\n"
f"Blob Size: {myblob.length} bytes")
connString = "<your_connection_string>"
blobserviceclient = bsc.from_connection_string(connString)
filepatharray = myblob.name.split("/")
sourcefilename = "/".join(filepatharray[1:])
logging.info(f"File Name is : {sourcefilename}")
destcontainer = ""
try:
blob = myblob.read()
json_data = json.loads(blob)
if(json_data):
destcontainer = "sink"
else:
destcontainer = "rejected"
logging.info(f"This is rejected file.")
blob_client = blobserviceclient.get_blob_client(container=destcontainer,blob=sourcefilename)
blob_client.upload_blob(blob)
logging.info(f"Blob Copied to {destcontainer}/{sourcefilename}")
except Exception as e:
destcontainer = "rejected"
blob_client = blobserviceclient.get_blob_client(container=destcontainer,blob=sourcefilename)
blob_client.upload_blob(blob)
logging.info(f"This file is Rejected. Blob Copied to {destcontainer}/{sourcefilename}")
logging.error(f"An error occurred: {e}")