Package com.hmkcode.vo

Examples of com.hmkcode.vo.FileMeta


   
     // 1. Get f from URL upload?f="?"
     String value = request.getParameter("f");
    
     // 2. Get the file of index "f" from the list "files"
     FileMeta getFile = files.get(Integer.parseInt(value));
    
     try {   
         // 3. Set the response content type = file content type
         response.setContentType(getFile.getFileType());
        
         // 4. Set header Content-disposition
         response.setHeader("Content-disposition", "attachment; filename=\""+getFile.getFileName()+"\"");
        
         // 5. Copy file inputstream to response outputstream
            InputStream input = getFile.getContent();
            OutputStream output = response.getOutputStream();
            byte[] buffer = new byte[1024*10];
           
            for (int length = 0; (length = input.read(buffer)) > 0;) {
                output.write(buffer, 0, length);
View Full Code Here


   
    // 2. Get paramter "twitter"
    String twitter = request.getParameter("twitter");

    // 3. Go over each part
    FileMeta temp = null;
    for(Part part:parts){ 

      // 3.1 if part is multiparts "file"
      if(part.getContentType() != null){
       
        // 3.2 Create a new FileMeta object
        temp = new FileMeta();
        temp.setFileName(getFilename(part));
        temp.setFileSize(part.getSize()/1024 +" Kb");
        temp.setFileType(part.getContentType());
        temp.setContent(part.getInputStream());
        temp.setTwitter(twitter);
       
        // 3.3 Add created FileMeta object to List<FileMeta> files
        files.add(temp);
       
      }
View Full Code Here

       
    List<FileMeta> files = new LinkedList<FileMeta>();
   
    // 1. Check request has multipart content
    boolean isMultipart = ServletFileUpload.isMultipartContent(request);
    FileMeta temp = null;
   
    // 2. If yes (it has multipart "files")
    if(isMultipart){

      // 2.1 instantiate Apache FileUpload classes
      DiskFileItemFactory factory = new DiskFileItemFactory();
      ServletFileUpload upload = new ServletFileUpload(factory);
     

      // 2.2 Parse the request
      try {
       
        // 2.3 Get all uploaded FileItem
        List<FileItem> items = upload.parseRequest(request);
        String twitter = "";
       
        // 2.4 Go over each FileItem
        for(FileItem item:items){
         
          // 2.5 if FileItem is not of type "file"
            if (item.isFormField()) {

              // 2.6 Search for "twitter" parameter
                if(item.getFieldName().equals("twitter"))
                  twitter = item.getString();
               
            } else {
              
              // 2.7 Create FileMeta object
              temp = new FileMeta();
            temp.setFileName(item.getName());
            temp.setContent(item.getInputStream());
            temp.setFileType(item.getContentType());
            temp.setFileSize(item.getSize()/1024+ "Kb");
           
              // 2.7 Add created FileMeta object to List<FileMeta> files
            files.add(temp);
              
            }
View Full Code Here

TOP

Related Classes of com.hmkcode.vo.FileMeta

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.