Exemplo n.º 1
0
  private void addVideoEverywhere(PrintWriter out, int projectId, File video)
      throws InvalidFileSizeException, IOException, ServiceException, NoSuchAlgorithmException {
    if (Security.isSafeVideo(video)
        && Security.videoFits(DatabaseApi.getNumberOfVideos(projectId))) {
      String[] videoUrlAndIcon = S3Api.uploadFile(video);
      String videoUrl = videoUrlAndIcon[0];
      String videoIcon = videoUrlAndIcon[1];
      if (videoUrl != null) {
        // Give the video a name only at the last moment to prevent duplicates.
        String videoName = Security.convertToSafeAndUniqueVideoName(video.getName(), projectId);
        DatabaseApi.addVideo(new Video(videoName, videoUrl, videoIcon, projectId, -1, -1, false));
        // File downloadedFile = S3Api.downloadFile(videoUrl); // TODO Add to /temp/ folder so it
        // can be played in the player.
        out.println("File uploaded. Please close this window and refresh the editor page.");
        out.println();

        return;
      }
      out.println("Upload Failed. Error uploading video to the cloud.");
      log.warning("Upload Failed. Error uploading video to the cloud.");
      // response.sendError(HttpServletResponse.SC_BAD_REQUEST);
      return;
    } else if (!Security.isSafeVideo(video)) {
      out.println("Upload Failed. Video is invalid.");
      log.warning("Upload Failed. Video is invalid.");
      return;
    } else if (!Security.videoFits(DatabaseApi.getNumberOfVideos(projectId))) {
      out.println("Upload Failed. Maximum number of videos reached.");
      log.warning("Upload Failed. Maximum number of videos reached.");
      return;
    } else {
      out.println("Upload Failed. Unknown reason.");
      log.warning("Upload Failed. Unknown reason.");
      // response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Bad Name");
      return;
    }
  }