Docker Container -- Querying files associated to entity

Hi @StarkRavenSimone,

In order to answer your question I’ll use a Version as an example. I’ll also be overly descriptive for the benefit of the wider community.

Fundamentally, most if not all files uploaded to Shotgun are stored as a File entity (the notable exception being thumbnails). The File entity in scripting terms is called Attachment and I’ll use that term in the rest of this response.

If you query a Version and ask for the fields that hold media, e.g. sg_uploaded_media you’ll get Attachment records back.

>>> sg.find_one('Version', [['id', 'is', 12345]])
>>> sg.find_one('Version', [['id', 'is', 12345]], ['sg_uploaded_movie'])
{'sg_uploaded_movie': {'name': 'some_filename.webm', 'url': 'http://some.site.com/file_serve/attachment/23456', 'content_type': 'video/webm', 'type': 'Attachment', 'id': 23456, 'link_type': 'upload'}, 'type': 'Version', 'id': 12345}

Once you have the Attachment record, you’ll have it’s id. Now, the actual files will be stored on the filesystem in a sub folder of <site_root>/shared/storage/production/files. This storage location will vary depending on the specifics of your setup (Shotgun Classic vs Shotgun Docker, if you’ve relocated the storage locations via symlink, etc…). The subfolder at this location where your Attachment is located will depend on the Attachment id. You’ll be looking for three consecutive sub folders which are represented by 3 groups of 4 digits built by padding the id with 0 up to 12 digits.

So an Attachment with an id of 23456, padded to 12 digits is 000000023456, then truncated into 3 groups is 0000/0002/3456.

In conclusion, the location you’ll be looking for will be <site_root>/shared/storage/production/files/0000/0002/3456/some_filename.webm.

For any entity type other than Version you’ll go though the same process. You’ll query for the relevant Attachment records, derive the path from the id and concatenate that to the storage location.

Do let me know if this covers what you were looking for and have a great weekend!

2 Likes