I am trying to upload raw JSON data on Google Cloud Platform. But I am getting this error:
TypeError: must be string or buffer, not dict
Code:
def upload_data(destination_path):
credentials = GoogleCredentials.get_application_default()
service = discovery.build('storage', 'v1', credentials=credentials)
content = {'name': 'test'}
media = http.MediaIoBaseUpload(StringIO(content), mimetype='plain/text')
req = service.objects().insert(
bucket=settings.GOOGLE_CLOUD_STORAGE_BUCKET,
body={"cacheControl": "public,max-age=31536000"},
media_body=media,
predefinedAcl='publicRead',
name=destination_path,
)
resp = req.execute()
return resp
Code Worked by changing StringIO(content) to StringIO(json.dumps(content))
from googleapiclient.discovery import build from googleapiclient import http from oauth2client.client import GoogleCredentials import iofor predefinedAcl options you can go here: cloud.google.com/storage/docs/access-control/… bucket needs to be the full name of your bucket. If you come from firebase it's "<name>.appspot.com"