Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Python存储在Firebase上的空文件_Python_Firebase_Firebase Storage_Pyrebase - Fatal编程技术网

使用Python存储在Firebase上的空文件

使用Python存储在Firebase上的空文件,python,firebase,firebase-storage,pyrebase,Python,Firebase,Firebase Storage,Pyrebase,我的目标是在Python服务器上生成某些文件(txt/pdf/excel),然后将其推送到Firebase存储 对于Firebase存储集成,我使用pyrebase包 到目前为止,我已设法在本地生成该文件,并随后将其存储在Firebase存储数据库的正确路径上 但是,我存储的文件总是空的。这是什么原因 1.生成本地文件 2.存储本地文件 #必需的库 输入基 导入时间 #Firebase设置和管理验证 配置={ “apiKey”:“, “authDomain”:“, “数据库URL”:“, “pr

我的目标是在Python服务器上生成某些文件(txt/pdf/excel),然后将其推送到Firebase存储

对于Firebase存储集成,我使用pyrebase包

到目前为止,我已设法在本地生成该文件,并随后将其存储在Firebase存储数据库的正确路径上

但是,我存储的文件总是空的。这是什么原因

1.生成本地文件 2.存储本地文件
#必需的库
输入基
导入时间
#Firebase设置和管理验证
配置={
“apiKey”:“,
“authDomain”:“,
“数据库URL”:“,
“projected”:“,
“storageBucket”:“,
“messagingSenderId”:”
}
firebase=pyrbase.initialize\u应用程序(配置)
storage=firebase.storage()
def fb_上载(本地文件):
#定义childref
childRef=“/test/test.txt”
storage.child(childRef).put(localFile)
#获取文件url
fbResponse=storage.child(childRef.get_url)(无)
返回响应

问题是我仅以写权限打开文件:

localFile = open(localFileName,"w+")
解决方案是关闭写入操作并以读取权限打开它:

# close (Write)
localFile.close()

# Open (Read)
my_file       = open(localFileName, "rb")
my_bytes      = my_file.read()

# Store on FB
fbUploadObj   = storage.child(storageRef).put(my_bytes)

我可以看看
.put(localFile)
localFile = open(localFileName,"w+")
# close (Write)
localFile.close()

# Open (Read)
my_file       = open(localFileName, "rb")
my_bytes      = my_file.read()

# Store on FB
fbUploadObj   = storage.child(storageRef).put(my_bytes)