Reputation: 3
I am using the following code to retrieve a file from the server so the client can download it. Is there any way I can find out which files have been downloaded? Maybe if a text file could be stored somewhere which could keep on adding filenames as they are downloaded are accessed?
function downloadPdf(){
//fetch the registrationId from the input#url
let registrationId = document.getElementById("url").value;
//transform the registrationId string to lower case
registrationId = registrationId.trim().toLowerCase();
const pdfUrl = `/ooecertificate/${registrationId}.pdf`;
//this is the statement to redirect the browser to the wanted url
//now commented because it wouldn't work here on the snippet
//window.location.href = pdfUrl;
//on its behalf I'm writing the url on console
console.log(pdfUrl); }
label.fieldLabel{
display: block;
margin-bottom: 1rem;
}
label.fieldDescription{
display: block;
margin-bottom: 1rem;
border: solid 1px gray;
padding: 1em;
}
button{
cursor: pointer;
}
<div>
<label class="fieldDescription">
Your registration id is your firstname+registered email id:<br>
For example..<br>
if your name is SAMMY DIXIT and your registered email id is [email protected]<br>
your REGISTRATION ID WILL BE: <b>[email protected]</b>
</label>
<label class="fieldLabel">ENTER YOUR REGISTRATION ID:</label>
<input type="text" name="url" id="url">
<button onclick="downloadPdf();">Download</button>
</div>
Upvotes: 0
Views: 72
Reputation: 11
There are two ways to store the download count information:
In a DATABASE
This would be the best way since you would have access to the database from anywhere.
The downside is that you have to implement a connection between a cloud-hosted database or a server-hosted database. Both ways you would have to pay for the service (although there are some free and limited alternatives).
In a FILE
You could store the information in a local .txt file and update it everytime a user clicks the download button but this would work only in the same computer and it's not recommended to do so
Hope this helps you
Upvotes: 1