0
votes

I am trying to upload a very long list of files to my fire-base bucket.I am using python and firebase admin Sdk. I get this error:

So here is the error that i get: google.api_core.exceptions.NotFound: 404 POST https://www.googleapis.com/upload/ storage/v1/b/gs://bismart-def3c.appspot.com/o?uploadType=resumable: ('Response headers must contain header', 'location')

import os
   import firebase_admin
   from firebase_admin import credentials, firestore, storage
   path = 'G:\\JURISPRUDENCE'

   files = []
   fileN = []

cred = credentials.Certificate("C:\Users\George\bismart-def3c-firebase-adminsdk-ib3f9-6a1f172321.json")
firebase_admin.initialize_app(cred, {
    'storageBucket': 'gs://bismart-def3c.appspot.com'
})


def upload(file,name):
    db = firestore.client()
    bucket = storage.bucket()
    blob = bucket.blob(name)
    outfile=file

    with open(outfile, 'rb') as my_file:
         blob.upload_from_file(my_file)   




# r=root, d=directories, f = files
for r, d, f in os.walk(path):
    for file in f:
        if '.docx' in file:
            files.append(os.path.join(r, file))
            upload(os.path.join(r, file),file)
            fileN.append(file)


for f in files:
    for k in fileN:
        print("uploaded" + k)

I currently dont succeed in making the upload

1
storageBucket should just be the name of the bucket with any prefixes like gs://Hiranya Jayathilaka

1 Answers

0
votes

I switched to google cloud/storage api. It has a very easy implementation: Just like that and i was able to upload my file:

def upload_blob(bucket_name, source_file_name, destination_blob_name):
    """Uploads a file to the bucket."""
    storage_client = storage.Client()
    bucket = storage_client.get_bucket(bucket_name)
    blob = bucket.blob(destination_blob_name)

    blob.upload_from_filename(source_file_name)

    print('File {} uploaded to {}.'.format(
        source_file_name,
        destination_blob_name))

As per the Docs. Hope it helps anyone looking