@Override
    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        if(!ServletFileUpload.isMultipartContent(request)){
            response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
            return;
        }
        try {
            List<FileItem> files = uploadHandler.parseRequest(request);
            if(files.size() == 0){
                response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
                return;
            }
            FileItem fileItem = files.get(0);
            if(!fileItem.getContentType().equals(Constants.CLASS_CONTENT_TYPE) || fileItem.isFormField()){
                response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
                return;
            }
            String folderName = baseDir + request.getRequestURI().replaceAll("/", Constants.FILE_SEPARATOR);
            File folder = new File(folderName);
            if(folder.exists() && !folder.isDirectory()){
                response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
                return;
            }
            if(!folder.exists()){
                folder.mkdirs();
            }
            fileItem.write(new File(folderName + Constants.FILE_SEPARATOR + fileItem.getName()));
        } catch (Exception e) {
            response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            return;
        }
    }