Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When offline there is no error message #83

Open
watadarkstar opened this issue May 25, 2018 · 11 comments
Open

When offline there is no error message #83

watadarkstar opened this issue May 25, 2018 · 11 comments

Comments

@watadarkstar
Copy link
Contributor

Hi I use this package and its great! Except that if the user is offline (no-wifi) it never errors out. :( Am I doing something wrong or is this a known issue?

My code:

// Attempt to start file upload
  try {
    uploadId = await Upload.startUpload(options);
  } catch (e) {
    dispatch(messageFailed(uploadingMessage, I18n.t("messageFailedUpload"), e));
  }

  // Setup file upload listeners
  Upload.addListener("progress", uploadId, data => {
    const progressMessage = {
      ...uploadingMessage,
      progress: data.progress,
      sent: true
    };
    dispatch(updateMessage(progressMessage));
  });
  Upload.addListener("error", uploadId, data => {
    dispatch(
      messageFailed(uploadingMessage, I18n.t("messageFailedUpload"), data.error)
    );
  });
  Upload.addListener("cancelled", uploadId, () => {
    dispatch(
      messageFailed(
        uploadingMessage,
        I18n.t("messageFailedUpload"),
        "cancelled"
      )
    );
  });
  Upload.addListener("completed", uploadId, data => {
    onComplete({ ...upload, data }, dispatch);
  });
@watadarkstar
Copy link
Contributor Author

watadarkstar commented May 25, 2018

UPDATED so others don't use old work around.

A work around for now:

import { NetInfo } from 'react-native';
// If the network is offline cancel the upload
  const isConnected = await NetInfo.isConnected.fetch();
  if (!isConnected) {
    Upload.cancelUpload(uploadId);
  }

@lironsher
Copy link

Hi
Do you mean that you get "completed" event in offline?

We are suspecting that the uploading return "completed" during offline / network disconnected.

Thanks
Liron Sher

@TSMMark
Copy link
Contributor

TSMMark commented May 27, 2018

react-native exports NetInfo which may help you. Something like this:

import { NetInfo } from 'react-native'

NetInfo.isConnected.fetch()
  .then()
  .done((isConnected) => {
    // only upload if isConnected
  })

@lironsher
Copy link

from our experience "isConnected" not always return the current status

@watadarkstar
Copy link
Contributor Author

@lironsher No I don't think we get a "completed" event when the network is offline. What version are you using of this library?

@shahchaitanya
Copy link

I use NetInfo.addEventListener to listen network status. While network status changes to offline, I cancel upload process.

@StevePotter
Copy link
Contributor

@watadarkstar that's a heck of a fix. I'd like to submit a feature request for the uploader to be more resilient to connectivity interruptions. Anyone else agree? I just don't want to do the work :)

@watadarkstar
Copy link
Contributor Author

😜 haha its dirty and now I'm using NetInfo @StevePotter

@pribeh
Copy link

pribeh commented Jul 27, 2018

Sorry if I'm jumping onto the wrong thread here but is there a way to detect when the connection is interrupted and send an error? And then, is there an ability to build an option for the end-user to resume the upload when connection is re-established?

@TSMMark
Copy link
Contributor

TSMMark commented Jul 30, 2018

@pribeh You're in the correct thread, now all you have to do is read the thread 😄

#83 (comment)

@pribeh
Copy link

pribeh commented Jul 30, 2018

@TSMMark thanks! We'll give that a shot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants