views:

32

answers:

1

I have some code which reads a file through a form field of type file

 <input type="file" ... />

I want to give the user another option of providing a url to a file rather than having to upload it as many are already online.

How can I detect when this field is empty on the server side. I am using Apache Commons FileUpload

FileItemStream item = iter.next();
    name = item.getFieldName();
    stream = item.openStream();
        if(!item.isFormField()){
            if(item.toString()!=""){
                ....

I need to detect when item is empty. The above code doesn't work, nor does using:

if(item.equals(null)){


    ....
+4  A: 

You can't call item.equals( null ) when item is null. You have to test it like this:

if( item == null ) {
   ...
}
tangens
Thanks - I thought i'd tried it but looks like it worked. I will accept your answer as soon as the time limit is up.
Ankur