How to upload a file to Google Cloud Storage on Python 3?

前端 未结 4 1069
刺人心
刺人心 2020-12-02 14:41

How can I upload a file to Google Cloud Storage from Python 3? Eventually Python 2, if it\'s infeasible from Python 3.

I\'ve looked and looked, but haven\'t found a

4条回答
  •  北海茫月
    2020-12-02 14:53

    Imports the Google Cloud client library (need credentials)

    from google.cloud import storage
    import os
    os.environ["GOOGLE_APPLICATION_CREDENTIALS"]="C:/Users/siva/Downloads/My First Project-e2d95d910f92.json" 
    

    Instantiates a client

    storage_client = storage.Client()
    
    buckets = list(storage_client.list_buckets())
    
    bucket = storage_client.get_bucket("ad_documents")//your bucket name
    
    blob = bucket.blob('/chosen-path-to-object/{name-of-object}')
    blob.upload_from_filename('D:/Download/02-06-53.pdf')
    print(buckets)
    

提交回复
热议问题