将一长串文件上传到Firebase存储

时间:2019-04-22 10:44:47

标签: python firebase-admin

我正在尝试将很长的文件列表上传到我的fire-base存储桶中。我正在使用python和firebase管理员Sdk。我收到此错误:

这是我得到的错误:google.api_core.exceptions.NotFound:404 POST https://www.googleapis.com/upload/ storage / v1 / b / gs://bismart-def3c.appspot.com/o?uploadType = resumable :(“响应标头必须包含标头”,“位置”)

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)

我目前未成功上传

1 个答案:

答案 0 :(得分:0)

我切换到了Google Cloud /存储api。它有一个非常简单的实现:就像这样,我能够上传我的文件:

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))

按照Docs。希望它能对任何有帮助的人