Note that there are some explanatory texts on larger screens.

plurals
  1. POUploading File in jsp or multipart/form-data
    primarykey
    data
    text
    <p>Actually I am trying to get no of files count to be uploading before uploading using common upload lib in jsp and I made a function for getting the counts of file this is here:</p> <pre><code>public static int getUploadFileCount(HttpServletRequest request) throws FileUploadException { int Result = 0; DiskFileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload upload = new ServletFileUpload(factory); List&lt;FileItem&gt; items = upload.parseRequest(request); for (FileItem item : items) { if (!item.isFormField()) Result++; } return Result; } </code></pre> <p>And use this function in business logic this here:</p> <pre><code>public void doChangeProfilePhoto(HttpServletRequest request) throws FileUploadException { if(UploadFileUtil.getUploadFileCount(request) != 1) throw new FileUploadException("There is Multiple/None File upload for Profile Photo. "); ProfileImage newProfileImage = new ProfileImage(); newProfileImage.setFileName("sam.jpg"); if(new UploadBPOProfilePhotoImpl().uploadPhoto(newProfileImage, request)) {} } </code></pre> <p>And in this code after calling uploadPhoto function there is also use same code for retrieving the files one by one like this:</p> <pre><code> DiskFileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload upload = new ServletFileUpload(factory); List&lt;FileItem&gt; items = upload.parseRequest(request); for (FileItem item : items) // Did not get file if i already used this code once For getting the files count: { if (!item.isFormField()) //did for makeing file and writing/saving it with a name } </code></pre> <p>So here I get problem is that when I use this code its not get file when I have used the same code for counting the files</p> <p>and if I comment this two line where I have use to get files count in doChangeProfilePhoto like this:</p> <pre><code>//if(UploadFileUtil.getUploadFileCount(request) != 1) // throw new FileUploadException("There is Multiple/None File upload for Profile Photo. "); </code></pre> <p>Then its working. Why its happening that if one time it is used so after it unable to retrieving the file.What's the reason behind it and is there any way to count files using common upload...and also for their names?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload