Package com.oreilly.servlet.multipart

Examples of com.oreilly.servlet.multipart.FilePart


        }
        existingValues.addElement(value);
      }
      else if (part.isFile()) {
        // It's a file part
        FilePart filePart = (FilePart) part;
        String fileName = filePart.getFileName();
        if (fileName != null) {
          filePart.setRenamePolicy(policy)// null policy is OK
          // The part actually contained a file
          filePart.writeTo(dir);
          files.put(name, new UploadedFile(dir.toString(),
                                           filePart.getFileName(),
                                           fileName,
                                           filePart.getContentType()));
        }
        else {
          // The field did not contain a file
          files.put(name, new UploadedFile(null, null, null, null));
        }
View Full Code Here


      mpp.setEncoding("UTF-8");
      Part part;
      boolean fileWritten = false;
      while ((part = mpp.readNextPart()) != null) {
        if (part.isFile() && !fileWritten) {
          FilePart fPart = (FilePart) part;
          String type = fPart.getContentType();
          // get file contents
          Tracing.logWarn(type + fPart.getFileName(), this.getClass());
          if (fPart != null && fPart.getFileName() != null && type.startsWith("text") && (type.toLowerCase().endsWith("calendar"))) {
           
            // store the uploaded file by a temporary name
            CalendarManager calManager = CalendarManagerFactory.getInstance().getCalendarManager();
            String calID = ImportCalendarManager.getTempCalendarIDForUpload(ureq);
            File tmpFile = calManager.getCalendarFile(CalendarManager.TYPE_USER, calID);
            fPart.writeTo(tmpFile);
           
            // try to parse the tmp file
            Object calendar = calManager.readCalendar(CalendarManager.TYPE_USER, calID);
            if (calendar != null) {
              fileWritten = true;
View Full Code Here

                                String[] valueArray = new String[1];
                                valueArray[0] = paramValue;
                                parameters.put(partName, valueArray);
                            }
                        } else if (attachmentPart.isFile()) {
                            FilePart filePart = (FilePart)attachmentPart;
                            String filename = filePart.getFileName();

                            MultipartDataSource fileUpload = null;
                            // check if this file has exceeded the maximum allowed upload size
                            if (noAttachments){
                                fileUpload = new MultipartDataSource(filename, "Exceeded file size allowed");
View Full Code Here

          // System.out.println("param: name=" + name + "; value=" +
          // value);
          params.put(name, value);
        } else if (part.isFile()) {
          // it's a file part
          FilePart filePart = (FilePart) part;
          String fileName = filePart.getFileName();
          String filePath = filePart.getFilePath();
          if (fileName != null) {
            boolean keepFileStru = "true"
                .equals(params
                    .get(IWebResConstants.FILE_PARA_KEEP_FILE_STRUCTURE));

            String relativePath = params
                .get(IWebResConstants.FILE_PARA_TARGET_RELATIVE_PATH);
            IPath newFilePath = null;
            if (keepFileStru && relativePath != null
                && relativePath.length() > 0) {
              newFilePath = new Path(tmpDir.getAbsolutePath())
                  .append(relativePath);
            } else
              newFilePath = new Path(tmpDir.getAbsolutePath())
                  .append(fileName);

            File newFile = newFilePath.toFile();
            createFile(newFile, false);
            long size = filePart.writeTo(new FileOutputStream(
                newFile));
            /*
             * System.out.println("file: name=" + name +
             * "; fileName=" + fileName + ", filePath=" +
             * filePart.getFilePath() + ", targetPath= " +
View Full Code Here

        if (name.equals("apiServerObjectId") && value instanceof FileApi)
          api = (FileApi)value;
        params.put(name, value);
       
      } else {
        FilePart filePart = (FilePart) part;
        String fileName = filePart.getFileName();
        if (fileName == null || fileName.trim().length() == 0)
          fileName = "unnamed-upload";
        filePart.setRenamePolicy(null);
        File file = ProxyManager.getInstance().createTemporaryFile(fileName);
        String uploadId = (String)params.get("uploadId");
        s_numberOfUploads++;
        if (uploadId == null)
          uploadId = "__UPLOAD_ID_" + s_numberOfUploads;
       
        log.info("Starting receive of " + file.getAbsolutePath());
        UploadingFile uploading = new UploadingFile(uploadId, file, fileName, params);
       
        File receivedFile = receiveFile(api, filePart.getInputStream(), uploading);
        FileInfo info = api.getFileInfo(receivedFile);
        if (info != null)
          files.add(info);
      }
    }
View Full Code Here

                String value = paramPart.getStringValue().trim();
                LOG.info("param; name=" + name + ", value=" + value);
                out.print("param; name=" + name + ", value=" + value);
            } else if (part.isFile()) {
                // it's a file part
                FilePart filePart = (FilePart) part;
                String fileName = filePart.getFileName();
                if (fileName != null) {
                    // the part actually contained a file
                    // StringWriter sw = new StringWriter();
                    // long size = filePart.writeTo(new File(System
                    // .getProperty("java.io.tmpdir")));
                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
                    long size = filePart.writeTo(baos);
                    LOG.info("file; name=" + name + "; filename=" + fileName + ", filePath=" + filePart.getFilePath() + ", content type=" + filePart.getContentType() + ", size="
                            + size);
                    out.print(String.format("%s: %s", name, new String(baos.toByteArray()).trim()));
                } else {
                    // the field did not contain a file
                    LOG.info("file; name=" + name + "; EMPTY");
View Full Code Here

TOP

Related Classes of com.oreilly.servlet.multipart.FilePart

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.