Package nl.oneday.data.domain.uploads

Examples of nl.oneday.data.domain.uploads.FileMeta


  @RequestMapping(value = Paths.UPLOAD, method = RequestMethod.POST)
  public @ResponseBody
  String upload(MultipartHttpServletRequest request, HttpServletResponse response) {
    UserDetails userDetails = getCurrentUserDetails();
    LinkedList<FileMeta> files = new LinkedList<FileMeta>();
    FileMeta fileMeta = null;
    JSONObject results = new JSONObject();
    // 1. build an iterator
    Iterator<String> itr = request.getFileNames();
    MultipartFile mpf = null;

    // 2. get each file
    while (itr.hasNext()) {

      // 2.1 get next MultipartFile
      mpf = request.getFile(itr.next());
      System.out.println(mpf.getOriginalFilename() + " uploaded! " + files.size());

      // 2.2 if files > 10 remove the first from the list
      if (files.size() >= 10) files.pop();

      // 2.3 create new fileMeta
      fileMeta = new FileMeta();
      fileMeta.setFileName(mpf.getOriginalFilename());
      fileMeta.setFileSize(mpf.getSize() / 1024 + " Kb");
      fileMeta.setFileType(mpf.getContentType());

      try {
        fileMeta.setBytes(mpf.getBytes());
      }
      catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
      // 2.4 add to files
      files.add(fileMeta);

      FileMeta savedFileMeta = writeFileToDisk(fileMeta);
      if (savedFileMeta != null) {
        nl.oneday.data.domain.uploads.File fileEntity = new nl.oneday.data.domain.uploads.File();
        fileEntity.setFilename(fileMeta.getFileName());
        fileEntity.setFilePath(uploadDirectory + userDetails.getUsername() + java.io.File.separator + fileMeta.getFileName());
        fileEntity.setType(fileMeta.getFileType());
View Full Code Here


  }


  private FileMeta writeFileToDisk(FileMeta fileMeta) {
    UserDetails userDetails = getCurrentUserDetails();
    FileMeta savedFileMeta = null;
    if (userDetails != null) {
      String userDirPath = uploadDirectory + userDetails.getUsername();
      java.io.File file = new java.io.File(userDirPath);
      if (!file.exists()) {
        try {
View Full Code Here

TOP

Related Classes of nl.oneday.data.domain.uploads.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.