Skip to content
This repository was archived by the owner on Oct 4, 2023. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Allow uploading file-like objects, allowing uploading of BytesIO/etc.
  • Loading branch information
khazhyk committed Mar 26, 2016
commit cb717fe7490d304f858f00b459166f8b42900300
6 changes: 4 additions & 2 deletions imgurpython/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,18 +580,20 @@ def get_image(self, image_id):
return Image(image)

def upload_from_path(self, path, config=None, anon=True):
with open(path, 'rb') as fd:
self.upload(fd, config, anon)

def upload(self, fd, config=None, anon=True):
if not config:
config = dict()

fd = open(path, 'rb')
contents = fd.read()
b64 = base64.b64encode(contents)
data = {
'image': b64,
'type': 'base64',
}
data.update({meta: config[meta] for meta in set(self.allowed_image_fields).intersection(config.keys())})
fd.close()

return self.make_request('POST', 'upload', data, anon)

Expand Down