Zotero storage key system

Hi,

I am trying to understand zotero's database schema and was wondering how storage keys are generated - they don't seem to be listed in the database and I need to automatically generate a list of all files associated with each item.

Thanks in advance for any help!
Tom
  • dstillman Zotero Team
    edited February 22, 2024
    Storage subfolders are item keys. They're in the items table in the database.
  • Thanks for the reply. I initially thought the same but it doesn't seem to be the case as the keys don't match the folder names - or at least the majority of keys don't match. This post (search for the word storage) confirms what I discovered:
    https://forums.zotero.org/discussion/comment/453010#Comment_453010

    Unless I'm missing something?
  • dstillman Zotero Team
    edited February 23, 2024
    You're going to have to trust me on this one. The folders are named after the item keys of attachment items.
  • Sorry for the delay - got distracted and picked this up again.

    I didn't trust you and now I do;)
    Thank you!
  • Thought i'd add the SQL query which returns a list of titles and storage keys for all items in a given collection (in this instance the collectionID of 215). What confused me what that the itemID's referred to in the collectionItems table don't identify the correct storage location key - its the parentItemID in the itemAttachments table which creates the relationship:


    SELECT
    c.collectionID,
    i.itemID as 'i.itemID',
    i.key,
    idv.value as 'title'
    FROM collections AS c
    JOIN collectionItems as ci ON c.collectioniD=ci.collectionID
    JOIN itemAttachments as ia ON ia.parentItemID=ci.itemID
    JOIN items as i ON i.itemID=ia.itemID
    JOIN itemData as id ON id.itemID=i.itemID
    JOIN itemDataValues as idv ON idv.valueID=id.valueID
    JOIN fieldsCombined as fc ON id.fieldID=fc.fieldID
    WHERE c.collectionID = 215
    AND fc.fieldName = 'title'


  • Thanks for the post. I have looked at the database, and I have understood it:

    - I have a file in the storage folder: Zotero/storage/7I4X9NPV
    - My item key: J8TQIS4Q

    When I look at the database:

    Table: ItemAttachments:
    - itemID: 112673, parentitem: 130419

    Table. Items:
    - itemID: 112673, key: 7I4X9NPV, libraryID: 5520790, itemTypeID: 14
    - itemID: 130419, key: J8TQIS4Q, libraryID: 5520790,itemTypeID: 34

    Table, ItemTypes:
    - ItemTypeID: 14, typeName: attachment
    - ItemTypeID: 34, typeName: document

    Therefore:
    - Items (folders and documents) are stored in the table.items.
    - The table.ItemAttachments stores the relationship between attachments (itemID) and documents (parentitem).
    - The key of items of type attachment in table.items corresponds to storage folders.

    Great! Thanks a lot!
Sign In or Register to comment.