views:

37

answers:

2

I have an webapp which dynamically generates a file and stores it on the server. When a user comes along, this file is served, after which it gets deleted. Each user gets their own generated file after which it becomes useless.

Is there a way to know if the user managed to download the file fully, so that it may be deleted and not clogging up my server with outdated files?

At the moment the problem is a user is clicking "Download file" then it being cancelled or failed, so they try again but its been deleted.

+1  A: 

There's no way to tell for certain whether the file was downloaded completely - even if you counted the bytes that the browser downloaded, what if their browser downloaded every byte of it but then crashed, for instance?

A common solution to this problem is to leave the file there for a predetermined period, then delete it. You tell the user "Your download will be available for the next 48 hours."

(The exact example above happened to me with Amazon's MP3 Store. I had to contact customer services for them to re-enable the download, which to their credit they did very quickly, but getting Customer Services involved for something like that is expensive.)

RichieHindle
Yea I thought as much, I'm sure I've looked into this problem before. Perhaps I could delete the file on some other event, like the user going to generate another file (i.e. it just overwrites the old one)
m.edmondson
A: 

Have the user click a "Continue" button after they download the file, and delete the file at that point.

Yuliy
and if they don't "continue" but do what most would and hit the back button, or close the window, or navigate to another site?
m.edmondson
At that point fall back to a timed expiration as was suggested by RichieHindle.
Yuliy