Skip to content
This repository was archived by the owner on Oct 4, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ Examples can be found [here](EXAMPLES.md)
### Image

* `get_image(image_id)`
* `upload_from_file(file, config=None, anon=True)`
* `upload_from_path(path, config=None, anon=True)`
* `upload_from_url(url, config=None, anon=True)`
* `delete_image(image_id)`
Expand Down
12 changes: 7 additions & 5 deletions imgurpython/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,22 +579,24 @@ def get_image(self, image_id):
image = self.make_request('GET', 'image/%s' % image_id)
return Image(image)

def upload_from_path(self, path, config=None, anon=True):
def upload_from_file(self, file, config=None, anon=True):
if not config:
config = dict()

fd = open(path, 'rb')
contents = fd.read()
contents = file.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)

def upload_from_path(self, path, config=None, anon=True):
with open(path, 'rb') as f:
return self.upload_from_file(f, config=config, anon=anon)

def upload_from_url(self, url, config=None, anon=True):
if not config:
config = dict()
Expand Down