public Object invoke(Object thiz, Object[] args) {

    final String remotePath = args[0].toString();
    final String localPath = args[1].toString();
    _onProgress = (ScriptableFunction) args[2];
    _onError = (ScriptableFunction) args[3];
    _options = (Scriptable) args[4];

    if (_onProgress != null) {
      _application.invokeLater(
          new Runnable() {
            public void run() {
              try {
                new Thread(
                        new Runnable() {
                          public void run() {

                            Object objToPassWithInvoke = null;

                            try {
                              byte[] b = readFile(localPath);
                              objToPassWithInvoke = postViaHttpConnection(remotePath, b);

                            } catch (IOException e) {
                              objToPassWithInvoke = e.getMessage();
                              // e.printStackTrace();
                            }
                            try {
                              if (objToPassWithInvoke != null) {
                                invokeCallback(objToPassWithInvoke);
                              }
                            } catch (final Exception e) {

                            } finally {

                            }
                          }
                        })
                    .start();
              } catch (final Exception e) {
              }
            }
          });
    }

    return Boolean.TRUE;
  }