@Override public void write(String filePath) throws Exception { String validFilePath = FileUploadUtils.getValidFilePath(filePath); fileItem.write(new File(validFilePath)); }
/** * Place the data from {@link FileItem} into the file location specified by this {@link FilePath} object. */ public void copyFrom(FileItem file) throws IOException, InterruptedException { if(channel==null) { try { file.write(writing(new File(remote))); } catch (IOException e) { throw e; } catch (Exception e) { throw new IOException(e); } } else { try (InputStream i = file.getInputStream(); OutputStream o = write()) { org.apache.commons.io.IOUtils.copy(i,o); } } }
for (FileItem item : formItems) { // processes only fields that are not form fields if (!item.isFormField()) { String fileName = new File(item.getName()).getName(); fileName1+=fileName; String filePath = uploadPath + File.separator + fileName; File storeFile = new File(filePath); // saves the file on disk item.write(storeFile); } else { //here... String fieldname = item.getFieldName(); String fieldvalue = item.getString(); if (fieldname.equals("p_data")) { //logic goes here... } else if (fieldname.equals("upload_wall_gallery")) { //next logic goes here... } } }
this.fileItem.write(dest); LogFormatUtils.traceDebug(logger, traceOn -> { String action = "transferred";
this.fileItem.write(dest); LogFormatUtils.traceDebug(logger, traceOn -> { String action = "transferred";
t.deleteOnExit(); try { fileItem.write(t); } catch (Exception e) {
public void write(final File file) throws IOException { try { fileItem.write(file); } catch (Exception e) { if (e instanceof IOException) { throw (IOException) e; } else { throw new IOException(e); } } }
public void writeTo(File pFile) throws IOException { try { item.write(pFile); } catch(RuntimeException e) { throw e; } catch (IOException e) { throw e; } catch (FileUploadException e) { // We deliberately change this exception to an IOException, as it really is throw (IOException) new IOException(e.getMessage()).initCause(e); } catch (Exception e) { // Should not really happen, ever throw new RuntimeException(e.getMessage(), e); } } }
@Override public void transferTo(@NonNull File dest) throws IOException, IllegalStateException { if (!isAvailable()) { throw new IllegalStateException("File has already been moved - cannot be transferred again."); } if (dest.exists() && !dest.delete()) { throw new IOException( "Destination file [" + dest.getAbsolutePath() + "] already exists and could not be deleted."); } try { fileItem.write(dest); } catch (FileUploadException ex) { throw new IllegalStateException(ex.getMessage(), ex); } catch (IllegalStateException ex) { // Pass through when coming from FileItem directly. throw ex; } catch (IOException ex) { // From I/O operations within FileItem.write. throw ex; } catch (Exception ex) { throw new IOException("File transfer failed", ex); } }
@Override public void writeTo(File target) throws IOException { requireNonNull(target, TARGET_CANNOT_BE_NULL); try { delegate.write(target); } catch (IOException e) { throw e; } catch (Exception e) { propagateIfPossible(e); throw new IOException(e); } }
@Override public void write(final String fileName) throws IOException { File file = new File(fileName); if (!file.isAbsolute()) { file = new File(location, fileName); } try { fileItem.write(file); } catch (Exception e) { throw new IOException(e); } }
List items = upload.parseRequest(httpRequest); Iterator iter = items.iterator(); File outputDir = getOutputDir(); while (iter.hasNext()) { FileItem item = (FileItem) iter.next(); String origName = item.getFieldName(); if ("dataFile1".equals(origName) { File outputFile = new File(outputDir, "firstFile.txt"); // This bit is doing the renaming item.write(outputFile); } // ... else all the other inputs get handled ... }
/** * Saves this file upload to a given file on the server side. * * @param file * The file * @throws Exception */ public void writeTo(final File file) throws Exception { Files.remove(file); item.write(file); }
/** * Saves this file upload to a given file on the server side. * * @param file * The file * @throws Exception */ public void writeTo(final File file) throws Exception { Files.remove(file); item.write(file); }
@Override public void write(File file) { try { item.write(file); } catch (Exception e) { throw new RuntimeException(UploadMessages.writeFailure(file), e); } }
String fileNames = ""; //to keep list of filenames for(FileItem item : multiparts){ if(!item.isFormField()){ fileNames += item.getName() + "; "; //add filename to string String name = new File(item.getName()).getName(); item.write( new File(UPLOAD_DIRECTORY + File.separator + name)); } } ..... ..... request.setAttribute("message", "File(s) Uploaded Successfully: " + fileNames );
use multipart form in jsp and server side use following code. for(FileItem item : multiparts){ if(!item.isFormField()){ String name = new File(item.getName()).getName(); item.write( new File(UPLOAD_DIRECTORY + File.separator + name)); request.setAttribute("photoname", name); }else{ // here get value of other parameter which is not file type System.out.println(item.getFieldName()+" = "+item.getString()); } }
for(FileItem item : multiparts){ if(!item.isFormField()){ String name = new File(item.getName()).getName(); item.write( new File(UPLOAD_DIRECTORY + File.separator + name)); request.setAttribute("photoname", name); }else{ // here get value of other parameter which is not file type System.out.println(item.getFieldName()+" = "+item.getString()); } }
public void accept(FileItem item) throws Exception { File dest = child(item.getName()); item.write(dest); try { unpack(dest); } catch (IOException e) { // problably should delete on error LOGGER.warning("Possible invalid file uploaded to " + dest.getAbsolutePath()); throw e; } }
DiskFileUpload upload = new DiskFileUpload(); List<FileItem> items = upload.parseRequest(request); // request is HttpServletRequest // iterate through form fields for(FileItem item:items) { if(item.isFormField()) { // text fields, etc... String fieldName = item.getFieldName(); String value = item.getString(); } else { // file fields item.write(new File("some/path")); } }