List of usage examples for javax.servlet.http Part delete
public void delete() throws IOException;
From source file:com.galenframework.storage.controllers.api.PageApiController.java
private FileInfo copyImageToStorage(Request req) throws IOException, ServletException { if (req.raw().getAttribute("org.eclipse.jetty.multipartConfig") == null) { MultipartConfigElement multipartConfigElement = new MultipartConfigElement( System.getProperty("java.io.tmpdir")); req.raw().setAttribute("org.eclipse.jetty.multipartConfig", multipartConfigElement); }//w w w . j av a 2s . c o m Part file = req.raw().getPart("file"); FileInfo imageInfo = fileStorage.saveImageToStorage(file.getInputStream()); file.delete(); return imageInfo; }
From source file:com.sishuok.chapter4.web.servlet.UploadServlet.java
@Override protected void doPost(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { try {// ww w . j av a 2 s .c om //servlet?Partnull //9.0.4.v20130625 ?? System.out.println(req.getParameter("name")); //?Part System.out.println("\n\n==========file1"); Part file1Part = req.getPart("file1"); //?? ?Part InputStream file1PartInputStream = file1Part.getInputStream(); System.out.println(IOUtils.toString(file1PartInputStream)); file1PartInputStream.close(); // ?? System.out.println("\n\n==========file2"); Part file2Part = req.getPart("file2"); InputStream file2PartInputStream = file2Part.getInputStream(); System.out.println(IOUtils.toString(file2PartInputStream)); file2PartInputStream.close(); System.out.println("\n\n==========parameter name"); //???? System.out.println(IOUtils.toString(req.getPart("name").getInputStream())); //Part??? jettyparameters?? System.out.println(req.getParameter("name")); //?? ? req.getInputStream(); ?? System.out.println("\n\n=============all part"); for (Part part : req.getParts()) { System.out.println("\n\n=========name:::" + part.getName()); System.out.println("=========size:::" + part.getSize()); System.out.println("=========content-type:::" + part.getContentType()); System.out .println("=========header content-disposition:::" + part.getHeader("content-disposition")); System.out.println("=========file name:::" + getFileName(part)); InputStream partInputStream = part.getInputStream(); System.out.println("=========value:::" + IOUtils.toString(partInputStream)); // partInputStream.close(); // ? ? ? part.delete(); } } catch (IllegalStateException ise) { // ise.printStackTrace(); String errorMsg = ise.getMessage(); if (errorMsg.contains("Request exceeds maxRequestSize")) { //? } else if (errorMsg.contains("Multipart Mime part file1 exceeds max filesize")) { //? ?? } else { // } } }
From source file:net.voidfunction.rm.master.AdminServlet.java
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setHeader("Date", HTTPUtils.getServerTime(0)); response.setContentType("text/html"); response.setStatus(HttpServletResponse.SC_OK); Part uploadFile = request.getPart("uploadfile"); if (uploadFile == null) throw new ServletException("Uploaded file is null."); // Get some info about the file String filename = getFilename(uploadFile); String contentType = uploadFile.getContentType(); long size = uploadFile.getSize(); byte[] hash = FileUtils.sha256Hash(uploadFile.getInputStream()); // Create a new file object, add it to the database, and store data RMFile newFile = new RMFile(filename, contentType, size, hash); node.getFileRepository().addFile(newFile, uploadFile.getInputStream()); // Output data for interested parties Template tpl = new Template(new File(templateDir + "uploadsuccess.tpl")); tpl.assign("FILENAME", filename); tpl.assign("SIZE", String.valueOf(size)); tpl.assign("TYPE", contentType); tpl.assign("HASH", Hex.encodeHexString(hash)); tpl.assign("FILEID", newFile.getId()); tpl.parse("main"); response.getWriter().print(tpl.out()); // Delete temp file uploadFile.delete(); // Log/*from w ww. j a v a 2s . c o m*/ node.getLog().info("New file added (via web): " + newFile.getId() + " (" + newFile.getName() + ")"); }
From source file:org.springframework.web.multipart.support.StandardServletMultipartResolver.java
@Override public void cleanupMultipart(MultipartHttpServletRequest request) { // To be on the safe side: explicitly delete the parts, // but only actual file parts (for Resin compatibility) try {// w w w . j ava2s . c om for (Part part : request.getParts()) { if (request.getFile(part.getName()) != null) { part.delete(); } } } catch (Throwable ex) { LogFactory.getLog(getClass()).warn("Failed to perform cleanup of multipart items", ex); } }