Publish files to Shotgun

I am trying to create code that publishes may work to shotgun and puts it into the correct place i got everything going except the file upload so it can create a publish with everything in That i want but it dosent want two do the upload it keeps on failing

So it is workin like this
nameofupload = ‘100_010_anim_v1’

comment = 'Plase or create interface for this2'

path = 'C:\Users\test\Desktop\REf\HTB1Cb.TSpXXXXazapXXq6xXFXXXT.jpg'

data = { 'project': {'type': 'Project','id': 92},
         'code': nameofupload,
         'description': comment,
         'sg_path_to_frames': path,
         'sg_status_list': 'rev',
         'entity': {'type': 'Asset', 'id': 1439},
         'sg_task': {'type': 'Task', 'id': 5822},
         'user': {'type': 'HumanUser', 'id': 88} }

result = shotgun.create("Version", data)

But if i add the lines that should add the file acording two what i understand it gives error here is code i used to make the file upload :

nameofupload = '100_010_anim_v1'
comment = 'Plase or create interface for this2'
path = 'C:\Users\test\Desktop\REf\HTB1Cb.TSpXXXXazapXXq6xXFXXXT.jpg'



uploadpath = {'link_type': 'upload', 'local_path': path, 'url' : path}

uploadpath = {'path': 'C:\\Users\\test\\Desktop\\REf', 'folder': 'C:\\Users\\test\\Desktop\\REf',    'extension': 'jpg', 'filename': 'BU-5b-013_9947.jpg'}

data = { 'project': {'type': 'Project','id': 92},
         'code': nameofupload,
         'description': comment,
         'this_file': uploadpath,
         'sg_path_to_frames': path,
         'sg_status_list': 'rev',
         'entity': {'type': 'Asset', 'id': 1439},
         'sg_task': {'type': 'Task', 'id': 5822},
         'user': {'type': 'HumanUser', 'id': 88} }

result = shotgun.create("Version", data)

Eni Help with this will be apreciated please even just telling me what i am doing wrong or something please

1 Like

Hi @WakaKrazyBunBun, welcome :slight_smile:

I’ve moved your post to the Shotgun category so that it’ll be in the right place, hope you don’t mind.

To begin, when uploading media to SG, you might have more success with the .upload() method, see this page for details: https://developer.shotgunsoftware.com/python-api/reference.html#shotgun_api3.shotgun.Shotgun.upload

You probably will want to create the Version entity first, and then upload your file to the Version you just created (using the returned Version id), pointing at the sg_uploaded_movie field, like so:

>>> data = {'project': {'type':'Project','id':99},'code':'test'}
>>> sg.create("Version",data)
{'project': {'type': 'Project', 'id': 99, 'name': 'multi entity test'}, 'code': 'test', 'type': 'Version', 'id': 1160704}
>>> sg.upload("Version",1160704,'magneto.jpg','sg_uploaded_movie')
663
>>>

That should hopefully get you up and running. :slight_smile:

2 Likes

O okay cool that was very helpful thank u still trying to find out how exactly the filter types and things are working for shotgun so i can query things easier

But thank u so much for the help i wanted to try and do it in one go but yeah dident think of doing it separate so thank u so much for your help

Also dont mind u moving it around i do hope this help someone else aswel thank u again

Sure thing :slight_smile:

If you’re looking for more info about filtering and queries, the Filter Syntax page might be of use, if you haven’t already found it: https://developer.shotgunsoftware.com/python-api/reference.html#filter-syntax

Probably really dumb question but is there eni thing i can read up on how this piece of code communicates with the rest of the code

That line is the return value from the previous upload() call executed in Tony’s example. Reading documentation on the upload function should have all the info regarding what is expected in the return values:

https://developer.shotgunsoftware.com/python-api/reference.html#shotgun_api3.shotgun.Shotgun.upload

1 Like