joltup / rn-fetch-blob

A project committed to making file access and data transfer easier, efficient for React Native developers.
MIT License
2.8k stars 767 forks source link

Upload to Dropbox not working #855

Open Stophface opened 8 months ago

Stophface commented 8 months ago

I am trying to upload a rather large file (~100mb) to Dropbox. The response I am getting from rn-fetch-blob is that it worked, however, there is a) nothing in my Dropbox and b) the upload takes about 1sec which is way too short for ~100mb.

  const _authenticateDropbox = async () => {
    const config = {
      clientId: '...',
      clientSecret: '...
      redirectUrl: 'org.reactjs.native.example..../oauth',
      scopes: [],
      serviceConfiguration: {
        authorizationEndpoint: 'https://www.dropbox.com/oauth2/authorize',
        tokenEndpoint: `https://www.dropbox.com/oauth2/token`,
      },
      additionalParameters: {
        token_access_type: 'offline',
      },
    };
    try {
      const user = await authorize(config);
      if (user) {
        if (user.accessToken) _uploadData(user.accessToken);
      }
    } catch (error) {
      console.warn('Something went wrong logging in into Dropbox, ', error);
    }
  };

  const _uploadData = accessToken => {
    const dbName = `${DATABASE_NAME}.db`;
    const databasePath = `${RNFS.DocumentDirectoryPath}/${dbName}`;

      RNFetchBlob.fetch(
        'POST',
        'https://content.dropboxapi.com/2/files/upload',
        {
          Authorization: accessToken,
          'Dropbox-API-Arg': JSON.stringify({
            path: '/foo.db',
            mode: 'add',
            autorename: true,
            mute: false,
          }),
          'Content-Type': 'application/octet-stream',
        },
        RNFetchBlob.wrap(databasePath),
      )
        .uploadProgress({interval: 250}, (written, total) => {
          ...
        })
        .then(res => {
          ...
        })
        .catch(error => {
          ...
        });
  };

Additionally, the total propb of uploadProgress() is 0 all the time. Am I doing something wrong?

Versions: "react-native": "0.71.7", "rn-fetch-blob": "^0.12.0",