Counting how many times file is downloaded

Hi,
In my web application I need to set the limit say 10 times, a file can be downloaded by the user. After downloading 10 times I need to disable the download link. I am using javascript,
ajax and spring framework and mysql .
Problem is when the file is being downloaded if the user clicks on cancel button of browser download manager or if they closes the browser , download count is incremented though the file is not downloaded completely. I need to catch the events when the download is incomplete so that I should not increment the download count that time.
Is there any way to solve this problem?
Please help me.....

I'm not sure if there's an easy way to do what you want to do.
You could try using a Servlet to serve the file though. What you'd basically need to do is set up a servlet to take a "file" parameter, load up the file, and then send it to the output stream. Once that was done you could increment the file download count.
So, in pseudo-code, what you'd be doing is:
doGet(HttpServletRequest request, HttpServletResponse response)
  String filename = request.getParameter("filename");
  File f = new File(FILE_DIR + filename);
  if (downloadCount < MAX_DOWNLOAD_COUNT)
    // TODO: Create FileInputStream and write contents to response.getOutputStream()
   // If you're using Spring, looking into the FileCopyUtils class as this will make it much easier
   // Increment download count
    downloadCount++;
}When someone clicks the "cancel" button on a download, you should find this closes the output stream, which will throw an exception and your download count will not be incremented. You might want to verify that though by testing it!
Of course, in the interests of security you would need to check that the filename being passed in didn't contain any special characters (particularly backslashes or forward slashes).
And I don't know how you're storing the download count, but of course you'd probably want to modify it so that it stored on a "per-file" basis!

Similar Messages

  • Something to count how many times form has downloaded

    Hi there.
    DW CS3, PHP mySQL
    I want to put on my site a PDF document that people can
    download.
    I don't want to link this to my mySQL DB for the records to
    be added in the
    DB.
    But, I want to see how many times this document has been
    downloaded.
    It's almost like "autonumber" in Access.
    I will really appreciate any advise and direction on how to
    accomplish
    this.
    Thanx so much.
    Deon

    Thanx Joe, I will check it out.
    I'm quickly building the download page.
    Deon
    Joe Makowiec <[email protected]> wrote in
    news:[email protected]:
    > On 14 Oct 2008 in macromedia.dreamweaver, Deon H wrote:
    >
    >> I want to put on my site a PDF document that people
    can download.
    >> I don't want to link this to my mySQL DB for the
    records to be added
    >> in the DB.
    >>
    >> But, I want to see how many times this document has
    been downloaded.
    >> It's almost like "autonumber" in Access.
    >> I will really appreciate any advise and direction on
    how to
    >> accomplish this.
    >
    > It's available in your logs. Just do a search for
    "myfile.pdf", and
    > look for lines which have a 200 status code. (Status
    code of 206
    > indicates a resumed download; you don't want to count
    those.) A
    > recent sample; details changed to protect the guilty:
    >
    > 192.168.4.246 - - [14/Oct/2008:01:56:04 +0000] "GET
    > /documents/town20080911.pdf HTTP/1.1" 200 20101
    > "
    http://www.example.org/minutes.asp"
    "Mozilla/4.0 (compatible; MSIE
    > 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)"
    192.168.4.246 - -
    > [14/Oct/2008:01:56:04 +0000] "GET
    /documents/town20080911.pdf
    > HTTP/1.1" 206 18572 "-" "Mozilla/4.0 (compatible; MSIE
    6.0; Windows NT
    > 5.1; SV1; .NET CLR 1.1.4322)"
    >
    > The first field is the IP address that the request came
    from
    > The second is date/time (in this case, in GMT)
    > The third is the request with protocol
    > The fourth is status code[1] followed by bytes
    transferred
    > The fifth is referrer; the sixth is user agent
    >
    > More information:
    http://www.w3.org/TR/WD-logfile.html
    >
    > [1]
    http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
    >

  • How many times can you download a song on iTunes and have it count?

    I'm wondering. Someone I like have released a song on iTunes and I wanna support them and I dont mind spending a few bucks on them.
    So how many times can I download a song and still have it count as an individual purchase? And what about gifting?
    thanks.
    -andy.

    As Polydorus said, get only one download per purchase for anything you buy from the iTunes Store other than iOS apps or iBooks. I'm not sure what you mean by "individual purchase" or what you are asking in reference to gifting.
    Regards.

  • Counting how many times my app has been opened

    I want to be able to count how many times a user has opened my application, and so every time the application launches, this number is added by one.
    Does anyone know how I store a long-time variable like this that will still need to be available across different runs of the application? I imagine this value would be stored in the application's preference file in Library, but I don't know how to do this.
    Can any of you please lend me some advice/code to achieve this (I am using Objective-C)?
    Thanks in advance,
    Ricky.

    Hi.
    It has been a while - but I finally got around to slapping some code together. I have successfully created and retrieved the value from the preference file, but for some reason, adding 1 to my value each run is not working. It only adds by one after each BUILD. So I have to rebuild it every time I want it to increment. See my code below;
    [NSUserDefaults init];
    int numberOfTimes;
    numberOfTimes = [[NSUserDefaults standardUserDefaults] integerForKey:@"used"];
    numberOfTimes = numberOfTimes++; //It is that that is not working.
    [[NSUserDefaults standardUserDefaults] setInteger:numberOfTimes forKey:@"used"];
    NSLog (@"%d", [[NSUserDefaults standardUserDefaults] integerForKey:@"used"]);
    I can't seem to stop anything wrong, but then again it is late.
    Do any of you see any errors here?
    Thanks,
    Ricky.

  • How to count how many times the caller calls by using UCCX script?

    Hi there,
    My customer wants to do a few changes for their script as below:
    At the beginning of the script they are planning to add a new menu item, it will announce their new privacy policies and to continue the user must press the number one to continue to the Welcome.  If they do not press 1 then the message should repeat itself and if they again do not press 1 they should be transferred over to a live operator who will explain things and then be able to transfer them back to the message so that they can press 1 and continue.
    I modified their script as attached file, but i don't know how to count how many times the caller calls in "Get Reporting Statistic".
    Any helps would be appreciated.
    Thanks.

    Hi Aaron,
    At beginning, i want to use a variable to get number of mistake for the same caller, then we will send the call to right place to fulfill the customers' needs. 
    Do you have any suggestion for the new posted script?
    Thanks.

  • How many times can you download

    hello
    how many times can i download the creative cloud set up?

    HI Philippa,
    You may install software on up to two computers. These two computers can be Windows, Mac OS, or one each.
    If you install on a third computer, it will request you to de-activate on the other two computers. You can then reactivate one of the previous two computers, and use Creative Cloud apps on it.
    If you regularly need to use the Creative Cloud on more than two computers then it would be best to purchase an additional subscription.
    An advantage though for Creative Cloud over the perpetual product is that you can install on Mac and Windows with the same subscription!
    Thanks,
    Ratandeep Arora

  • How many times can I download from Adobe Creative Cloud, and on how many computers

    I just purchased a one month plan from Adobe Creative Cloud and already downloaded several programs.  Unrelated to Adobe, I reinstalled the operating system on my computer today.  I just downloaded the programs again.  Is there a limit on how many times I can download Adobe software?   I also am planning on purchasing another computer down the road.  How many computers can I download Adobe software from my current Adobe Creative Cloud membership. 
    Thanks-

    You can download and install it as many times as you like but you must activate it in order to use it.
    You can only activate the software on a maximum of two computers at any one time.
    You can deactivate on a computer via Help > Deactivate and re-activate via the same step.

  • How many times can i download 2.1?

    I bought a 2.1 update in the itunes store on my computer. But it has been download for many times and never succeed. So i wanna know whether downloading it for several times costs more money? And how many times can I download it?

    I can't speak directly about 2.1, but iTunes should give you an alert that you've already download the app. It shouldn't bill you again. It should still be on your computer.
    What do you mean "it has been downloaded (sp.) many times and has (sp.) never succeeded (sp.)"? What was it unsuccessful in doing?

  • How many times can i download photoshop or lightroom?

    hi how many times can I download photoshop or lightroom? I bought and downloaded them onto my lap top but want to put it onto a pc can I do that? or is it a one time down load only

    You have 2 activations, so yes, you can use it on both systems.
    Mylenium

  • How many times can I download my music from icloud

    How many times can I download music from Icloud?

    Welcome to the Apple Community.
    You can download it as many times as you want.

  • How many times can I download Quick Time Pro once I purchased it?

    Last September I purched my update to Quick Time Pro. Now I bought a new Computer and re-formatted the old one, not being able to copy Quick Time Pro from the old to the new computer. Therefore I wanted to download again Quick Time Pro: In the settings window I introduced my program key and then "accepted". It said "Quick Time pro" below the registration line; however, the "apply" buttom was not operative. I checked and my Quick Time version was still "Quick Time 7", not Pro. My question is: how many times can I download Quick Time Pro once I purched it? If I can download it more often than once, how do I proceed? Thank you for your help.

    I started this thread:
    http://discussions.apple.com/thread.jspa?threadID=2454706&tstart=0
    but I'm afraid it's so involved that thus far, nobody has "touched" it.
    However, PART of my problem is similar to THIS person's.
    My problem is that I have QT on two different drives in one computer; the one I paid for [QT Pro?] and one I got for free; QT7. I fear the free QT7 might have "interfered" with my "Pro".
    So, taking your advice above, looking in the "Help" "About" menu, I find that BOTH of mine another "offer" above the word "About"; they suggest that I "Purchase QT Pro"...... so now, if BOTH of my QT's say THAT, then may I conclude that I do NOT have the Pro version? I'm meaning to say that if I already HAVE the Pro, they wouldn't suggest that I go and "Buy QT Pro".... right? Is this a safe conclusion? for ya'll that HAVE the Pro, and KNOW it, does it suggest to you that you could go and "purchase QT Pro"?
    Thanks,
    LarryR : )

  • How many times can I download this product??

    I got photoshop elements 10 for Christmas. How many times can I download it onto computers??? Can I put it on multiple computers??

    If you mean how many times can you install it, your license lets you install it on two computers. If you want to install it on more computers than that, you'll need to deactivate one of the installs (Editor>Help>Deactivate).

  • How many times can I download a movie from iTunes?

    I recently purchased some of the movies offered in the bundled sales and am curious how many times I can download them.  Will they always be in the cloud, or do I exceed a limited number of views or downloads at a certain point?  I suppose if I did exceed a limited number of views from my Apple TV, or downloads from iTunes to my computer, I should then back them up.
    Thanks for any guiance you guys may offer!

    If you are in a country where you can re-download films, and if the studio allows re-downloading, then you will be able to re-download them as many times as you like - but there is no guarantee that they will remain in the store (studios occasionally remove them), so you are better off keeping your own backup copy of them (and similarly with your other downloads) rather than relying on them remaining in the store

  • Hey! On excel I want to count how many time a text come back in the spreadshit (sum) thx, hey! On excel I want to count how many time a text come back in the spreadshit (sum) thx

    Excel:
    line of cellule with 3 different text. I want to count have many time a text come in the line... Thx for helping me, it is for my job!!

    Hopefully I am understanding your question.
    A typical way to count how many times a word appears in a line of text in a cell is to substitute spaces for the word, one less space than the length of the word. Example:
    A1 has the string "brown red brown green"
    A2 =LEN(A1) - LEN(SUBSTITUTE(A1,"brown","    "))  
    "brown" has five letters so there are four spaces in the substitution text)
    If you want to do several cells at once, counting the total number of times the word appears, concatenate the cells with a space between them
    A1 and A2 have text in them
    A3 =LEN(A1&" "&A2) - LEN(SUBSTITUTE(A1&" "&A2,"brown","    "))

  • HT5148 how many times can I download it?

    how many times can I download it?

    The limit is in how many machines you can install your copy to. Check this FAQ for the details-
    http://support.apple.com/kb/HT5148

Maybe you are looking for

  • Abt module pool

    Hi,      can i declare a selection screen in module pool program?      can i use at selection-screen event in module pool program?

  • LMS 3.2 CiscoWorks Daemon Manager does not startup

    When trying to start CiscoWorks Daemon Manager i get the following message: "The CiscoWorks Daemon Manager service on local computer started and the stoped. Some services stop automatically if they are not in use by other services or programs." I hav

  • Problem with multiple requests

    I have a problem with the users submitting multiple requests simultaneously. Let me put it this way: 1. User is on a tabbed panel with clear and search buttons. 2. User clicks on 'clear' button from any tab (request one). On successful completion, it

  • I am unable to download itunes to PC

    I recently purchased an iPod and when I try to download iTunes, it refuses to work. I have windows 7 and 64-bit operation system. I have disabled firewall and pop-up blocker, nothing works. I tried to download different versions, that doesn't work. I

  • How to i update my ios for my ipod touch to 5.0.1

    I have another ipod touch and ipad with version 5.0.1 and I want to update my other ipod touch to the same version, so we can share all of our apps. However, I am forced to try to update to version 6.0.1 - I cannot update to this version. I have trie