Skip to content

Commit afa364a

Browse files
author
Samuel Waugh
committed
Merge pull request #100 from shotgunsoftware/ticket/34463-upload-thumbnail
Ticket/34463 upload thumbnail
2 parents 38c7648 + 031a369 commit afa364a

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

shotgun_api3/shotgun.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1425,7 +1425,7 @@ def upload_thumbnail(self, entity_type, entity_id, path, **kwargs):
14251425
:returns: Id of the new attachment
14261426
"""
14271427
return self.upload(entity_type, entity_id, path,
1428-
field_name="thumb_image", **kwargs)
1428+
field_name="image", **kwargs)
14291429

14301430
def upload_filmstrip_thumbnail(self, entity_type, entity_id, path, **kwargs):
14311431
"""Convenience function for uploading filmstrip thumbnails.
@@ -1443,7 +1443,7 @@ def upload_filmstrip_thumbnail(self, entity_type, entity_id, path, **kwargs):
14431443
"higher, server is %s" % (self.server_caps.version,))
14441444

14451445
return self.upload(entity_type, entity_id, path,
1446-
field_name="filmstrip_thumb_image", **kwargs)
1446+
field_name="filmstrip_image", **kwargs)
14471447

14481448
def upload(self, entity_type, entity_id, path, field_name=None,
14491449
display_name=None, tag_list=None):
@@ -1470,7 +1470,8 @@ def upload(self, entity_type, entity_id, path, field_name=None,
14701470
if not os.path.isfile(path):
14711471
raise ShotgunError("Path must be a valid file, got '%s'" % path)
14721472

1473-
is_thumbnail = (field_name == "thumb_image" or field_name == "filmstrip_thumb_image")
1473+
is_thumbnail = (field_name in ["thumb_image", "filmstrip_thumb_image", "image",
1474+
"filmstrip_image"])
14741475

14751476
params = {
14761477
"entity_type" : entity_type,
@@ -1483,7 +1484,7 @@ def upload(self, entity_type, entity_id, path, field_name=None,
14831484
url = urlparse.urlunparse((self.config.scheme, self.config.server,
14841485
"/upload/publish_thumbnail", None, None, None))
14851486
params["thumb_image"] = open(path, "rb")
1486-
if field_name == "filmstrip_thumb_image":
1487+
if field_name == "filmstrip_thumb_image" or field_name == "filmstrip_image":
14871488
params["filmstrip"] = True
14881489

14891490
else:

tests/test_api.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,19 @@ def test_upload_thumbnail_for_task(self):
318318
self.version['id'], {'image': None})
319319
expected_clear_thumbnail = {'id': self.version['id'], 'image': None, 'type': 'Version'}
320320
self.assertEqual(expected_clear_thumbnail, response_clear_thumbnail)
321+
322+
def test_upload_thumbnail_with_upload_function(self):
323+
"""Upload thumbnail via upload function test"""
324+
size = os.stat(path).st_size
321325

326+
# upload thumbnail
327+
thumb_id = self.sg.upload("Task", self.task['id'], path, 'image')
328+
self.assertTrue(isinstance(thumb_id, int))
329+
330+
#upload filmstrip thumbnail
331+
f_thumb_id = self.sg.upload("Task", self.task['id'], path, 'filmstrip_image')
332+
self.assertTrue(isinstance(f_thumb_id, int))
333+
322334
def test_linked_thumbnail_url(self):
323335
this_dir, _ = os.path.split(__file__)
324336
path = os.path.abspath(os.path.expanduser(

0 commit comments

Comments
 (0)