Any good solution for limiting total number of files selected?

Hey all,

I am using SWF Upload to allow users to upload photos to a photo album. This photo album has a limited size. I am trying to find a way to present the user with a good solution to fail gracefully when they select more files than the album size.

For example, lets say the album size is X and I set the the file_queue_limit and file_upload_limit to X . Lets say the user selects (X + 1) files to upload. Then the alert error pops up saying "too many files selected" and their selection history in the previous window is gone and they have to reselect the proper amount of files.

I want a solution that
1) Limits the amount of files they upload
2) Does not loose the history of their file selection

A possible solution I am thinking about is giving them an infinite file_upload_limit and file_queue_limit, but cancel all the files queued at indexes >= X

Anyone else have a good solution?

gyphie's picture

Sounds good

Your solution is what I would have suggested. Let them queue up as many files as they want. Then either cancel any "over-queue" files or alert them and let them cancel the files they want.

You'll have to track the remaining allow spots and the number of files queued (available from the getStats function).

my pseduo code

So I did exactly that. Basically all the files selected are added to the queue but once that threshold is reached, a cancel the file from swfupload. Below is my pseudocode in case any one else ever has the same questoin

on event fileQueued(file)
if totPhotos + queuedPhotos < maxPhotots
set pending status
queuedPhotos++
else
swfupload.cancelUpload(file.id)

on event uploadError(file, errorCode, message)
if(errorCode == SWFUpload.UPLOAD_ERROR.FILE_CANCELLED)
set album full status