W. Stephens
W. Stephens

Reputation: 779

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.

Upvotes: 1

Views: 3396

Answers (1)

Brandon Yarbrough
Brandon Yarbrough

Reputation: 38379

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)

Upvotes: 4

Related Questions