Skip to content
This repository was archived by the owner on Nov 26, 2024. It is now read-only.

Commit 6bbce8f

Browse files
committed
Storage put handle files
1 parent 72ba145 commit 6bbce8f

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Pyrebase [![](https://img.shields.io/pypi/v/Pyrebase.svg)](https://pypi.python.org/pypi/Pyrebase)
1+
# Pyrebase
22

33
A simple python wrapper for the [Firebase API](https://firebase.google.com).
44

pyrebase/pyrebase.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -312,20 +312,26 @@ def child(self, *args):
312312
self.path = new_path
313313
return self
314314

315-
def put(self, file_name, token=None):
315+
def put(self, file, token=None):
316316
# reset path
317317
path = self.path
318318
self.path = None
319319
if token:
320-
file = open(file_name, 'rb')
320+
if isinstance(file, str):
321+
file_object = open(file, 'rb')
322+
else:
323+
file_object = file
321324
request_ref = self.storage_bucket + "/o?name={0}".format(path)
322325
headers = {"Authorization": "Firebase "+token}
323-
request_object = self.requests.put(request_ref, headers=headers, data=file)
326+
request_object = self.requests.put(request_ref, headers=headers, data=file_object)
324327
raise_detailed_error(request_object)
325328
return request_object.json()
326329
elif self.credentials:
327330
blob = self.bucket.blob(path)
328-
return blob.upload_from_filename(filename=file_name)
331+
if isinstance(file, str):
332+
return blob.upload_from_filename(filename=file)
333+
else:
334+
return blob.upload_from_file(file_obj=file)
329335

330336
def delete(self, name):
331337
self.bucket.delete_blob(name)

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
setup(
44
name='Pyrebase',
5-
version='3.0.6',
5+
version='3.0.7',
66
url='https://github.com/thisbejim/Pyrebase',
77
description='A simple python wrapper for the Firebase API',
88
author='James Childs-Maidment',

0 commit comments

Comments
 (0)