简体   繁体   中英

How to upload a JSON to google cloud storage using python

I am trying to load this code to upload a json to my google cloud via python.

import boto
import gcs_oauth2_boto_plugin
import os
import shutil
import StringIO
import tempfile
import time

from google.cloud import storage
from google.cloud.storage import blob

client = storage.Client(project='dataworks-356fa')
bucket = client.get_bucket('dataworks-356fa-backups')
blob = ('t.json', bucket)
with open('t.json', 'rb'):
  blob.upload_from_file('t.json')

I am following the guideline on here ...

I am stuck and do not know where to go so any help will be greatly appreciated. I have changed the blob.upload_from_file('t.json') with blob.upload('t.json') and get the same problem.

It looks like you're trying to use an instance of the class Blob but are using a tuple by mistake. Try this:

client = storage.Client(project='dataworks-356fa')
bucket = client.get_bucket('dataworks-356fa-backups')
blob = bucket.blob('t.json')
with open('t.json', 'rb') as json_file:
  blob.upload_from_file(json_file)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM