将长文件列表上载到firebase storag

2024-10-01 22:33:45 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图上传一个很长的文件列表到我的firebase桶,我使用python和firebase管理Sdk。我得到这个错误:

我得到的错误是:google.api_核心.异常。未找到:404后https://www.googleapis.com/upload/ 存储/v1/b/gs://bismart-def3c。appspot.com/o?uploadType=可恢复:('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)

我目前无法成功上传


Tags: pathinimportcomforbucketadminos
1条回答
网友
1楼 · 发布于 2024-10-01 22:33:45

我转而使用google云/存储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。希望它能帮助任何人

相关问题 更多 >

    热门问题