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

Error while file upload to dropbox #97

Open
ugeshgupta000 opened this issue Nov 18, 2024 · 4 comments
Open

Error while file upload to dropbox #97

ugeshgupta000 opened this issue Nov 18, 2024 · 4 comments
Assignees
Labels
awaiting-user-feedback Awaiting user feedback

Comments

@ugeshgupta000
Copy link

I am trying to use node-mongotools package with dropbox upload. I have set the relevant tokens for getting long lived token, but i get below error:


uploadErr TypeError: _this3.fetch is not a function
    at <unknown> (turbopack://[project]/node_modules/dropbox/es/src/dropbox.js:160:22)
  158 |         return fetchOptions;
  159 |       }).then(function (fetchOptions) {
> 160 |         return _this3.fetch(baseApiUrl(host, _this3.domain, _this3.domainDelimiter) + path, fetchOptions);
      |                      ^
  161 |       }).then(function (res) {
  162 |         return parseResponse(res);
  163 |       });

Code snippet:


var mongoTools = new MongoTools();
const mtOptions = {
    uri: getDbUri(''), // Empty to take backup for all databases.
    // dropboxToken: process.env.DROPBOX_TOKEN,
    dropboxAppKey: process.env.DROPBOX_APIKEY,
    dropboxAppSecret: process.env.DROPBOX_APISECRET,
    dropboxRefreshToken: process.env.DROPBOX_REFRESHTOKEN,
    path: 'data/backups'
};

export const createMongoDbDump = async () => {
    // mongoTools.list(mtOptions).then((x: any) => console.log(x));

    const result = await mongoTools
        .mongodump(mtOptions)
        .catch((err: any) => console.error("Mongodb backup job error =>", err));
    console.log(result);

    // We may delete the backup file which is created in backup folder on FS.
    // For now, keeping it as is, since storage might not be a problem currently.
}
@boly38
Copy link
Owner

boly38 commented Nov 18, 2024

hi ugeshgupta000 👋 and thanks for your question

arg, I'm unable to reproduce on my side by playing locally test
it seems to be dropbox internal lib issue (wrong handling of negative usecase)

  • adding MT_DROPBOX_DEBUG=true could provide you a little bit more context. but that wont fix.

It's maybe related to dropbox token .. and you could play with boly38/dropbox-refresh-token and especially with launch step by step to get refreshToken to double-check your environment values.

I keep interested to help you with this issue to improve current repository, let me know about updates or if you found more precise way to reproduce
cheers

@boly38 boly38 added the awaiting-user-feedback Awaiting user feedback label Nov 18, 2024
@boly38
Copy link
Owner

boly38 commented Nov 19, 2024

after cloning repo locally,
I just play with this extra file simpleUploadTest.js (that isolate dropbox upload/list feature only)
and I have no issue on my side :|

import MongoTools from "../../lib/MongoTools.js";
import MTOptions from "../../lib/MTOptions.js";

const options = new MTOptions()
const mt = new MongoTools();

const list = () => {
    mt.dbx.listFromDropbox(options)
        .then(console.log)
        .catch(console.error)
}

const upload = () => {
    // generate  10MB file (linux) : dd if=/dev/zero of=/WORK/node-mongotools/output.dat  bs=1024  count=10240
    // generate 148MB file (linux) : dd if=/dev/zero of=/WORK/node-mongotools/output.dat  bs=1024  count=151240
    // generate 156MB file (linux) : dd if=/dev/zero of=/WORK/node-mongotools/output.dat  bs=1024  count=159240
    mt.dbx.mongoDumpUploadOnDropbox(options, {"fullFileName":"./output.dat"})
}

const firstArg = process.argv[2];
if (firstArg === "list")
    list();
else if (firstArg === "options")
    console.log(options);
else if (firstArg === "upload")
    upload(); // think to remove it before new test
else
    console.log("??")

example of use

MT_DROPBOX_DEBUG=true node simpleUploadTest.js upload

dropbox api & limit

  • dropbox fileUpload documentation (method doc in node_modules/dropbox/types/index.d.ts) talk about 150MB limitation but maybe n your usecase you're producing and tryng to upload an huge file? what was your file size ?
  • the same doc is talking about current plan and transport limit page : https://www.dropbox.com/developers/reference/data-transport-limit

@ugeshgupta000
Copy link
Author

First of all, sorry it took quite some time to get back. Apologies for that.

So i checked the refresh utility, and if i set the same appKey, secret and refreshToken there, then it determines the credentials as successful.
image

However, if i am using the same credentials with node-mongotools, it throws this error:


isValid:false error:invalid_access_token/ - so dropboxRefreshAccessToken
Dropbox upload /data/backups/all__2024-11-30_022545.gz:
uploadErr TypeError: _this3.fetch is not a function
    at <unknown> (turbopack://[project]/node_modules/dropbox/es/src/dropbox.js:160:22)
  158 |         return fetchOptions;
  159 |       }).then(function (fetchOptions) {
> 160 |         return _this3.fetch(baseApiUrl(host, _this3.domain, _this3.domainDelimiter) + path, fetchOptions);
      |                      ^
  161 |       }).then(function (res) {
  162 |         return parseResponse(res);
  163 |       });
Mongodb backup job error => Error: Dropbox upload /data/backups/all__2024-11-30_022545.gz: [status:undefined] undefined
    at <unknown> (turbopack://[project]/node_modules/node-mongotools/lib/MTDropbox.js:64:39)
  62 |                                 const {status, error} = uploadErr;
  63 |                                 const errorMessage = `Dropbox upload ${dbxFilename}: [status:${status}] ${error?.error_summary}`;
> 64 |                                 reject(new Error(errorMessage));
     |                                       ^
  65 |                             });
  66 |                     });
  67 |                 })
undefined

@boly38 boly38 self-assigned this Dec 4, 2024
@boly38
Copy link
Owner

boly38 commented Dec 4, 2024

FYI / I tried with extra exploratory tests on Dropbox({"accessToken value

  • extra bad char but supported : got 401 from dbx as expected
  • extra bad char not supported as header (ex. \n \x01) : got is not a legal HTTP header value from node-fetch (make sense)

unfortunately, I'm unable to reproduce exactly this dbx issue.
If someone get an howto reproduce, please append this issue 🙏

Maybe double check all versions used (ex. npm list dropbox), including nodejs. What s size is your dump?

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

No branches or pull requests

2 participants