question

Anusha-7854 avatar image
0 Votes"
Anusha-7854 asked JayaC-MSFT answered

How to save JSON content to Azure blob storgae in Azure funtions blob trigger

I am writing an azure function blob trigger to read the input CSV file into a pandas data frame and I am passing one specific column values in API request, and I want to save its response(JSON content) into Blob storage with .json type.


outputBlob.set(str(nhtsa_data)) is not writing output to .json file

 import logging
 import azure.functions as func
 from azure.storage.blob import BlobServiceClient,BlobClient
 import pandas as pd
 import requests
 import json
 import os, io
    
    
 def main(inputBlob: func.InputStream, outputBlob: func.Out[str]):
     logging.info(f"Blob trigger executed!")
     logging.info(f"Blob Name: {inputBlob.name} ({inputBlob.length}) bytes")
     logging.info(f"Full Blob URI: {inputBlob.uri}")
        
     connection_string  = "DefaultEndpointsProtocol=https;AccountName=nhtsa;AccountKey=345345345sdf/w==;EndpointSuffix=core.windows.net"
     containerName = "myblobcontainer"
     blobName = "input/NHTSA_Inbound.csv"
     out_blob = "output"
     blob = BlobClient.from_connection_string(conn_str=connection_string, container_name=containerName, blob_name=blobName)
     blob_service_client = BlobServiceClient.from_connection_string(connection_string)
    

        
    
    
    
     blobStream = blob.download_blob().content_as_bytes()
     logging.info(blobStream)
     df = pd.read_csv(io.BytesIO(blobStream), sep=',', dtype=str)
     vin_df = pd.DataFrame(df['vin'])
     vin_tup = list(vin_df.to_records(index=False))
     for i,t in enumerate(vin_tup):
         nhtsa_url = 'https://vpic.nhtsa.dot.gov/api/vehicles/DecodeVinValuesExtended/%s?format=json&modelyear=2011'%t[0]
         nhtsa_req_content = requests.get(nhtsa_url)
         nhtsa_data = nhtsa_req_content.json()
         outputBlob.set(str(nhtsa_data))
azure-functionsazure-blob-storage
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

JayaC-MSFT avatar image
0 Votes"
JayaC-MSFT answered

Hello @Anusha-7854 Welcome to Microsoft QnA. Thank you for the question. I am looking into it. However, in the meantime , You may refer to https://stackoverflow.com/questions/61790607/how-do-i-receive-multipart-form-data-in-azure-function/63305138#63305138

Here a file has been saved to blob.

Please let me know if this helps.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.