Issue about uploading a file to Files

Hey everyone:

I was trying to upload a file from analysis without success.

My code:

const account = new Account({ token: env_vars.account_token });
const testBuffer = Buffer.from("hello world", "utf-8");
const filename = "test.csv";

const response = await account.files.uploadFile(testBuffer, filename, {
  contentType: "text/csv",
});

// also tested with promises .then() & .catch()

Error throws

(node:98094) UnhandledPromiseRejectionWarning: Error: Could not upload part number 1: undefined
    at Files._addToQueue (/my_project/node_modules/@tago-io/sdk/out/modules/Account/Files.js:217:27)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:98094) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 6)
(node:98094) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
error uploading Error: Could not upload part number 1: undefined
    at Files._addToQueue (/my_project/node_modules/@tago-io/sdk/out/modules/Account/Files.js:217:27)

Anyhow, i’ve just changed the upload function and it worked, but i’m really don’t like much Base64.

const response = await account.files.uploadBase64([
  {
    filename: `/my_csv_files/${filename}`,
    file: testBuffer.toString("base64"),
  },
]);

Thanks!

Hi @cesar.pinto,

On a quick look I’ve seen that you’re missing two required fields in the “options” parameter, see → Options | TagoIO SDK for JavaScript and TypeScript

I’m not sure if this will solve your problem upfront, but try this →

  const response = await account.files.uploadFile(testBuffer, filename, {
    contentType: "text/csv",
    isPublic: true,
    onProgress: () => {},
  });

Let us know. Thanks.
-Guilherme

1 Like

That worked, thanks Guilherme!!

1 Like