Docker Container -- Querying files associated to entity


Currently the only way that I know of getting attachment file locations on the server is by using the docker list_files_in_project script.
Is there a way to do this for other entities (primarily version and notes)?


1 Like

Hey @StarkRavenSimone,

Thank you for the post. I will flag this to our TS team and will get an answer to you soon.


Hi @StarkRavenSimone,

when you say “Is there a way to do this for other entities”, are you asking if there’s a way to list all Versions and Notes, or are you asking if there’s a way to get attachment file locations, but filtered? Or did you mean something else? If you could expand on your use case and desired results, that would be most helpful :slight_smile:

1 Like

Also, moving this topic to the Shotgun category for better categorization.

1 Like

I’m specifically looking for a method to see where attachment files associated to a particular entity ID are located in the SG server media folder.
In most cases this will be versions, notes and deliveries.

1 Like

Ah, okay. Thanks for the clarification. I’m not sure we have any tools for that specifically, but I will dig around a little and get back to you.

1 Like

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': '', '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!