Ejemplo n.º 1
0
  private void fileUpload() throws Exception {
    httpPost = new NUHttpPost(uploadURL);

    MultipartEntity mpEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);

    mpEntity.addPart("akey", new StringBody(fileCloudAccount.getFileCloudAPIKey()));

    mpEntity.addPart("Filedata", createMonitoredFileBody());
    httpPost.setEntity(mpEntity);
    NULogger.getLogger().log(Level.INFO, "executing request {0}", httpPost.getRequestLine());
    NULogger.getLogger().info("Now uploading your file into filecloud.io .....");
    uploading();
    httpResponse = httpclient.execute(httpPost);
    HttpEntity resEntity = httpResponse.getEntity();
    NULogger.getLogger().info(httpResponse.getStatusLine().toString());
    if (resEntity != null) {
      stringResponse = EntityUtils.toString(resEntity);
    }

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

    if (!"ok".equals(responseStatus)) {
      // Handle errors
      throw new Exception("Error: " + jSonObject.getString("message"));
    }

    String downloadURL = "http://filecloud.io/" + jSonObject.getString("ukey");
    NULogger.getLogger().log(Level.INFO, "Download link : {0}", downloadURL);
    downURL = downloadURL;

    status = UploadStatus.UPLOADFINISHED;
  }
Ejemplo n.º 2
0
  @Override
  public void run() {
    try {

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

      addExtensions();

      // Check extension
      if (!FileUtils.checkFileExtension(allowedExtensions, file)) {
        throw new NUFileExtensionException(file.getName(), host);
      }

      uploadInitialising();

      httpPost = new NUHttpPost(uploadURL);
      MultipartEntity mpEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
      mpEntity.addPart("file", createMonitoredFileBody());
      httpPost.setEntity(mpEntity);

      NULogger.getLogger().log(Level.INFO, "executing request {0}", httpPost.getRequestLine());
      NULogger.getLogger().info("Now uploading your file into AnonFiles.com");
      uploading();
      httpResponse = httpclient.execute(httpPost);
      responseString = EntityUtils.toString(httpResponse.getEntity());

      // Read the links
      gettingLink();
      jSonObject = new JSONObject(responseString);
      if (jSonObject.getString("status").equals("success")) {
        downloadlink = jSonObject.getString("url");
        NULogger.getLogger().log(Level.INFO, "Download link : {0}", downloadlink);
      } else {
        throw new Exception("Upload failed: " + jSonObject.getString("msg"));
      }

      downURL = downloadlink;

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

      uploadFailed();
    }
  }
Ejemplo n.º 3
0
  @Override
  public void run() {
    try {
      if (slingFileAccount.loginsuccessful) {
        host = slingFileAccount.username + " | SlingFile.com";
        httpContext = slingFileAccount.getHttpContext();
      } else {
        host = "SlingFile.com";
        cookieStore = new BasicCookieStore();
        httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
      }

      if (file.length() > fileSizeLimit) {
        throw new NUMaxFileSizeException(
            fileSizeLimit, file.getName(), slingFileAccount.getHOSTNAME());
      }
      uploadInitialising();
      initialize();

      httpPost = new NUHttpPost(postURL);
      MultipartEntity mpEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
      mpEntity.addPart("X-Progress-ID", new StringBody(progressID));
      mpEntity.addPart("uFileID", new StringBody(progressID));
      mpEntity.addPart("uid", new StringBody(encUserID));
      if (slingFileAccount.loginsuccessful) {
        mpEntity.addPart("folderid", new StringBody("0"));
      }
      mpEntity.addPart("ssd", new StringBody(ssd));
      mpEntity.addPart("Filename", new StringBody(file.getName()));
      mpEntity.addPart("name", new StringBody(file.getName()));
      mpEntity.addPart("Upload", new StringBody("Submit Query"));
      mpEntity.addPart("file", createMonitoredFileBody());
      httpPost.setEntity(mpEntity);
      NULogger.getLogger().log(Level.INFO, "executing request {0}", httpPost.getRequestLine());
      NULogger.getLogger().info("Now uploading your file into slingfile.com");
      uploading();
      HttpResponse response = httpclient.execute(httpPost, httpContext);
      stringResponse = EntityUtils.toString(response.getEntity());

      if ("done".equals(stringResponse)) {
        NULogger.getLogger().log(Level.INFO, "upload done!");

        gettingLink();
        httpGet = new NUHttpGet(URILink);
        httpResponse = httpclient.execute(httpGet, httpContext);

        stringResponse = EntityUtils.toString(httpResponse.getEntity());
        // FileUtils.saveInFile("SlingFile.com.html", stringResponse);
        Document doc = Jsoup.parse(stringResponse);
        downloadlink =
            doc.select("div#container div#mainContent fieldset table tbody tr td input")
                .first()
                .val();
        deletelink =
            doc.select("div#container div#mainContent fieldset table tbody tr td input")
                .eq(3)
                .val();

        NULogger.getLogger().log(Level.INFO, "Delete link : {0}", deletelink);
        NULogger.getLogger().log(Level.INFO, "Download link : {0}", downloadlink);
        downURL = downloadlink;
        delURL = deletelink;
      } else {
        throw new Exception("Upload isn't good.");
      }

      uploadFinished();
    } catch (Exception e) {
      Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, e);

      uploadFailed();
    }
  }