How to read json file in cloud storage using cloud functions - python

raj S

The need is to read the json file data present in GCS bucket using cloud functions (python). I have uploaded the required json data to bucket and try running the cloud function.

The input json file data :

{"count":15,"data":[{"P_ID":21.0,"P_NAME":"MMME","TZ":"PST","DATE_MODIFIED":"2005-10-14 00:00:00"}]}

here is the code:

    from google.cloud import storage
    import base64
    import json
    import os
    
def hello_gcs(event, context):
    """
    Triggered by a change to a Cloud Storage bucket.
    Args:
         event (dict): Event payload.
         context (google.cloud.functions.Context): Metadata for the event.
    """
    print("in CF")  
    print("event", event)

    file_name = event['name']
    bucket_name = event['bucket']
    client = storage.Client()
    bucket = client.get_bucket(bucket_name)
    file_blob = storage.Blob(file_name, bucket)
    download_data = file_blob.download_as_string().decode()
    jsondata = {}
    jsondata = download_data
    print("download_data : ", download_data)
    print("jsondata := ", jsondata)
    print(jsondata['count'])

Please correct me. I am not getting the data displayed in the code. this is just to test the cloud function once this is working I need to implement additional features.

guillaume blaquiere

The function that you use if triggered on an event, when an object is written to Cloud Storage for instance. But you only have the event, not the content. With the event data, you have all that you need for downloading the file and to process it.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Read JSON file directly from google storage (using Cloud Functions)

From Dev

modify existing json in cloud storage using cloud functions - python

From Dev

How to write a list to a file in Google Cloud Storage using Google Cloud Functions with Python

From Dev

How to read content of JSON file uploaded to google cloud storage using node js

From Dev

Read a CSV from Google Cloud Storage using Google Cloud Functions in Python script

From Dev

How to Read .json file in python code from google cloud storage bucket

From Dev

How to get file content and move file to different Google Cloud Storage using Google Cloud functions

From Dev

How to send a file from cloud storage using response.sendFile in cloud functions?

From Dev

How do I read the contents of a new cloud storage file of type .json from within a cloud function?

From Dev

How to read json file from blob storage using Azure Functions Blob Trigger with Python

From Dev

How to upload a JSON to google cloud storage using python

From Dev

Delete file in cloud storage from cloud functions

From Dev

Delete a file from firebase storage using download url with Cloud Functions

From Dev

Error while uploading file to Firebase Storage using Firebase Cloud Functions

From Dev

Read JSON file content from google cloud storage bucket

From Dev

How to delete a file using Cloud Functions?

From Dev

How to read simple text file from Google Cloud Storage using Spark-Scala local Program

From Dev

How to read a huge CSV file from Google Cloud Storage line by line using Java?

From Java

GCS - Read a text file from Google Cloud Storage directly into python

From Dev

GCP Cloud Storage file push by python using service account json file

From Dev

Read huge JSON line by line from Google Cloud Storage with Python

From Dev

How to read a file from a cloud storage bucket via a python app in a local Docker container

From Dev

How to read a Google Cloud Storage file from Google App Engine

From Dev

How to iterate over Firebase Storage using Cloud Functions

From Dev

Read Shapefile from Google Cloud Storage using Dataflow + Beam + Python

From Dev

Cloud Functions, Cloud Firestore, Cloud Storage: How to protect against bots?

From Dev

Can't download file using google cloud storage and Cloud Functions for Firebase

From Dev

Cloud Functions and Storage: Is deleting file asynchronous?

From Dev

Cloud functions: Delete file from storage

Related Related

  1. 1

    Read JSON file directly from google storage (using Cloud Functions)

  2. 2

    modify existing json in cloud storage using cloud functions - python

  3. 3

    How to write a list to a file in Google Cloud Storage using Google Cloud Functions with Python

  4. 4

    How to read content of JSON file uploaded to google cloud storage using node js

  5. 5

    Read a CSV from Google Cloud Storage using Google Cloud Functions in Python script

  6. 6

    How to Read .json file in python code from google cloud storage bucket

  7. 7

    How to get file content and move file to different Google Cloud Storage using Google Cloud functions

  8. 8

    How to send a file from cloud storage using response.sendFile in cloud functions?

  9. 9

    How do I read the contents of a new cloud storage file of type .json from within a cloud function?

  10. 10

    How to read json file from blob storage using Azure Functions Blob Trigger with Python

  11. 11

    How to upload a JSON to google cloud storage using python

  12. 12

    Delete file in cloud storage from cloud functions

  13. 13

    Delete a file from firebase storage using download url with Cloud Functions

  14. 14

    Error while uploading file to Firebase Storage using Firebase Cloud Functions

  15. 15

    Read JSON file content from google cloud storage bucket

  16. 16

    How to delete a file using Cloud Functions?

  17. 17

    How to read simple text file from Google Cloud Storage using Spark-Scala local Program

  18. 18

    How to read a huge CSV file from Google Cloud Storage line by line using Java?

  19. 19

    GCS - Read a text file from Google Cloud Storage directly into python

  20. 20

    GCP Cloud Storage file push by python using service account json file

  21. 21

    Read huge JSON line by line from Google Cloud Storage with Python

  22. 22

    How to read a file from a cloud storage bucket via a python app in a local Docker container

  23. 23

    How to read a Google Cloud Storage file from Google App Engine

  24. 24

    How to iterate over Firebase Storage using Cloud Functions

  25. 25

    Read Shapefile from Google Cloud Storage using Dataflow + Beam + Python

  26. 26

    Cloud Functions, Cloud Firestore, Cloud Storage: How to protect against bots?

  27. 27

    Can't download file using google cloud storage and Cloud Functions for Firebase

  28. 28

    Cloud Functions and Storage: Is deleting file asynchronous?

  29. 29

    Cloud functions: Delete file from storage

HotTag

Archive