PDFs do not download correctly using "Find Full Text"
On a number of items PDFs are not downloaded correctly when right-clicking "Find Full Text". The same PDFs can be downloaded manually from an anonymous Firefox profile from the same computer without any requirement to separately login or anything. My computer is based on the university campus. I am on a Windows computer, using Zotero 10.0.2
Trying to debug this further, a curl command (copied from the anonymous Firefox instance using "copy as cURL (Windows)") retrieves the PDF correctly, while removing the cookie from the curl request returns an unauthenticated response (e.g. referring to HTML with a paywall). Apparently, upon a first request a cookie is added to the request, leading to it being able to download a PDF. Presumably, some automated authentication is happening in the background (again, there is no manual authentication necessary) leading to some cookies being generated allowing the request to retrieve proper PDF.
From within Zotero itself, I tested the connections using Javascript (Tools > Developer > Run Javascript). The following code correctly retrieves a PDF:
let r = await Zotero.HTTP.request("GET",
"https://www.nature.com/articles/s41586-023-06221-2.pdf",
{ responseType: "text" });
return [r.status, r.getResponseHeader("Content-Type"), r.responseText.length];
the following does not retrieve a PDF (with the relevant item selected):
let item = Zotero.getActiveZoteroPane().getSelectedItems()[0];
return await Zotero.Attachments.importFromURL({
url: "https://www.nature.com/articles/s41586-023-06221-2.pdf",
parentItemID: item.id,
contentType: "application/pdf"
});
There somehow seems to be a different code path used in Zotero.Attachments.importFromURL compared to Zotero.HTTP.request that somehow results in the former not retrieving a PDF correctly while the latter is retrieving a PDF correctly.
Trying to debug this further, a curl command (copied from the anonymous Firefox instance using "copy as cURL (Windows)") retrieves the PDF correctly, while removing the cookie from the curl request returns an unauthenticated response (e.g. referring to HTML with a paywall). Apparently, upon a first request a cookie is added to the request, leading to it being able to download a PDF. Presumably, some automated authentication is happening in the background (again, there is no manual authentication necessary) leading to some cookies being generated allowing the request to retrieve proper PDF.
From within Zotero itself, I tested the connections using Javascript (Tools > Developer > Run Javascript). The following code correctly retrieves a PDF:
let r = await Zotero.HTTP.request("GET",
"https://www.nature.com/articles/s41586-023-06221-2.pdf",
{ responseType: "text" });
return [r.status, r.getResponseHeader("Content-Type"), r.responseText.length];
the following does not retrieve a PDF (with the relevant item selected):
let item = Zotero.getActiveZoteroPane().getSelectedItems()[0];
return await Zotero.Attachments.importFromURL({
url: "https://www.nature.com/articles/s41586-023-06221-2.pdf",
parentItemID: item.id,
contentType: "application/pdf"
});
There somehow seems to be a different code path used in Zotero.Attachments.importFromURL compared to Zotero.HTTP.request that somehow results in the former not retrieving a PDF correctly while the latter is retrieving a PDF correctly.
Upgrade Storage