Exemple #1
0
  @Override
  public void run() {

    try {
      if (fileCloudAccount.loginsuccessful) {
        host = fileCloudAccount.username + " | FileCloud.io";
      } else {
        host = "FileCloud.io";

        uploadInvalid();
        return;
      }

      // Check file size (max)
      if (file.length() > maxFileSizeLimit) {
        throw new NUMaxFileSizeException(maxFileSizeLimit, file.getName(), host);
      }

      // Check file size (min)
      if (file.length() < minFileSizeLimit) {
        throw new NUMinFileSizeException(minFileSizeLimit, file.getName(), host);
      }

      uploadInitialising();
      NULogger.getLogger().info("Getting upload url from FileCloud.....");
      stringResponse =
          NUHttpClientUtils.getData(
              "http://api.filecloud.io/api-fetch_upload_url.api?response=json");

      // Get JSONObject
      jSonObject = new JSONObject(stringResponse);
      String responseStatus = jSonObject.getString("status");

      if ("ok".equals(responseStatus)) {
        uploadURL = jSonObject.getString("upload_url");
        NULogger.getLogger().log(Level.INFO, "FileCloud Upload URL : {0}", uploadURL);
        fileUpload();
        uploadFinished();
      } else {
        // Handle errors
        throw new Exception("Error: " + jSonObject.getString("message"));
      }

    } catch (NUException ex) {
      ex.printError();
      uploadInvalid();
    } catch (Exception e) {
      Logger.getLogger(FileCloud.class.getName()).log(Level.SEVERE, null, e);

      uploadFailed();
    }
  }
Exemple #2
0
  /** Upload with normal uploader. */
  public void normalUpload() throws IOException, Exception {
    String uploadPostUrl;
    NUHttpPost httppost;
    HttpResponse response;
    String reqResponse;

    uploadPostUrl = "https://upload.firedrive.com/web";

    // Getting vars
    final String getUrl = "http://www.firedrive.com/upload?_=" + System.currentTimeMillis();
    reqResponse = NUHttpClientUtils.getData(getUrl, httpContext);
    final String vars = StringUtils.stringBetweenTwoStrings(reqResponse, "return '", "'");

    NULogger.getLogger().log(Level.INFO, "getUrl: {0}", getUrl);
    NULogger.getLogger().log(Level.INFO, "vars: {0}", vars);

    // Start the upload
    uploading();

    httppost = new NUHttpPost(uploadPostUrl);
    MultipartEntity mpEntity = new MultipartEntity();
    mpEntity.addPart("name", new StringBody(file.getName()));
    mpEntity.addPart("vars", new StringBody(vars));
    mpEntity.addPart("target_folder", new StringBody("0"));
    mpEntity.addPart("target_group", new StringBody("0"));
    mpEntity.addPart("file", createMonitoredFileBody());
    httppost.setEntity(mpEntity);
    response = httpclient.execute(httppost, httpContext);
    reqResponse = EntityUtils.toString(response.getEntity());

    JSONObject jSonObject = new JSONObject(reqResponse);

    if (jSonObject.getString("result").equals("success")) {
      // Now we can read the link
      gettingLink();
      downURL = "http://www.firedrive.com/file/" + jSonObject.getString("id");
      NULogger.getLogger().log(Level.INFO, "Download URL: {0}", downURL);
    } else {
      // Handle errors
      NULogger.getLogger().info(reqResponse);
      throw new Exception("Error in firedrive.com. Take a look to last jSonObject!");
    }
  }