GAE / J - Blobstore - how to determine if the file is not downloaded


I am working on web application and using GAE/J blobstore tutorial I was able to upload file to blobstore.

My Problem is my "upload file" option is OPTIONAL on form. So user may or maynot choose to upload the file on my form. So since this field is optional, I do not have any upfront form validation for this field, but then when i submit the form "a blank document with 0kb file gets uploaded to blobstore" since i am not able to determine if user has selected any file or not inside servlet.

I tried Apache file upload (ServletFileUpload..etc) but it keeps returning null everytime.

so not sure, how do i determine if user have selected any file to upload inside servlet?

            Map<String, BlobKey> blobs = blobstoreService.getUploadedBlobs(req);
            if (blobs != null && blobs.size() > 0) {
                BlobKey blobkey = blobs.get("myFile");
                blobkeyStr = blobkey.getKeyString();

You can test if a blob was uploaded by checking the size of the blob. If the size is zero, you should delete the blob.

BlobstoreService bs = BlobstoreServiceFactory.getBlobstoreService();
BlobKey blobKey = bs.getUploads(req).get("blob").get(0);
final BlobInfo blobInfo = new BlobInfoFactory().loadBlobInfo(blobKey);
long size = blobInfo.getSize();
if(size > 0){
  //process blob