Can we create FileItem object from given file name and file location using Java? If we use commons-fileupload jar we can upload file using jsp/html and in servlet on parsing request we will get List<FileItem>. But I want to do file upload using plain java where I want to create FileItem object manually (I don't want to use byte[] array to store the file). So is there any way to create FileItem object manually?
1 Answer
Yes, you can.
Use the DiskFileItemFactory like this:
DiskFileItemFactory factory = new DiskFileItemFactory(); FileItem fi = factory.createItem("formFieldName", "application/zip", false, "/var/temp/somefile.zip"); Obviously use content type and other parameters appropriate to your case.
3ncG1vNJzZmirpJawrLvVnqmfpJ%2Bse6S7zGiorp2jqbawutJoaW1vZ2iDdICOnJinZaeaeqS%2BxJqrnmWWnrmmtdOepGankp%2BypMCMn6mopV2btq2xjKeYpp1dlrulecuompqsmaS7