'Can I rename a file on download with a useful name based on other page elements?
This is part of the code from a website that lets me download thousands of documents. Unfortunately each document is named document.tif on downloading, and the website doesn't give an ability to change this. Is it in principle possible to write a javascript script to download the file on click and to rename it meaningfully. The body of the website looks like this. A meaningful name would be
"07 23 2012 Affidavit Declaration Certificate Confirmation of Service.tif" for example in this case.
<li class="list-group-item">
<div class="portal-case-event" data-event-description="Affidavit Declaration Certificate Confirmation of Service">
<div class="tyler-toggle-controller open">
<p class="text-primary">
07/23/2012 Affidavit Declaration Certificate Confirmation of Service
<span class="caret"> </span>
</p>
</div>
<div class="tyler-toggle-container row-buff" style="display:block;overflow:hidden">
<p>
<a data-dialog-width="819"
class="btn btn-default document-download"
data-dialog-title="Document Viewer"
data-doc-doctype="Public"
data-doc-docname="AFFIDAVIT_DCLR_CERT OF SERVICE "
data-doc-doctypeid="2"
id="docLink_kF95cQdRJeWK3WbATbVPWQ2"
href="/ODYPORTAL/DocumentViewer/Display?eid=kF95cQdRJeWK3WbATbVPWQ2&docTypeId=2&caseNum=12-3-02040-1&locationId=410&caseId=0zS1WUOxtmgteZLUMLjI5w2&docType=Public&docName=AFFIDAVIT_DCLR_CERT+OF+SERVICE+&eventName=Affidavit+Declaration+Certificate+Confirmation+of+Service"
style="margin-right: 10px;">
View Document
</a>
<span class="text-muted">
AFFIDAVIT_DCLR_CERT OF SERVICE
</span>
</p>
<p class="col-sm-12 col-md-12">
<span class="text-muted">Comment</span>
<br> 4: AFFIDAVIT/DCLR/CERT OF SERVICE;
</p>
</div>
</div>
Solution 1:[1]
You can try this following code ?
<a download="YourCustomFileName.tif" href="Link-to-download">Download</a>???????????????????????????
This attribute download with a tag came with HTML5. This attribute lets you rename the file.
PS: This attribute only works with same-origin URLs.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Dupinder Singh |
