JavaScript API: Dowload attachment and get its file location

47 views
Skip to first unread message

Christian Boulanger

unread,
Jan 9, 2022, 4:42:20 AM1/9/22
to zotero-dev
Hi, as it ismarked as "to do" in the docs and I couldn't find something on the list, here's another question on the JavaScript API:

Using the API, how can I detect if an attachment has been downloaded, force the download if it hasn't, and then get the file location of the downloaded attachment to do something with it (I want to programmatically download via a connector endpoint to be consumed by an external script).

Thank you.

Christian Boulanger

unread,
Jan 9, 2022, 9:51:19 AM1/9/22
to zotero-dev
I've got the "find attachment file location" part, using getFilePath()  or getFilePathAsync(),  but I wasn't able to figure out how to force the download of file. How could this be done?

let collection = ZoteroPane.getSelectedCollection();
let items = collection.getChildItems();
let item = items[0];
let attachment = Zotero.Items.get(item.getAttachments()[0]);
let filepath = await attachment.getFilePathAsync();
if (!filepath) {
    // force download, wait for download to complete
    filepath = await attachment.getFilePathAsync();
}
Reply all
Reply to author
Forward
0 new messages