Writing Files to Tago

Hello,

I am trying to write a text file to the Files area from an analysis. I can write a base64 file (as per a community post) but the uploadFile always generates an error.

Minimum code below to replicate issue:

Any ideas what I missed?

const {
Analysis,
Account,
Utils
} = require("@tago-io/sdk");

async function writeFileTest(context) {
const envVars = Utils.envToJson(context.environment);

const account = new Account({
token: envVars.account_token
});
const testBuffer = Buffer.from(“hello world”, “utf-8”);

// THIS WORKS
const response = await account.files.uploadBase64([{
filename: “test1.txt”,
file: testBuffer.toString(“base64”),
contentType: “text/txt”,
public: true
}, ]);

// THIS THROWS AN EXCEPTION (BELOW)
const response2 = await account.files.uploadFile(
testBuffer,
“text2.txt”, {
isPublic: true,
contentType: “text/txt”,
onProgress: () => {}
}
);

}

// To run analysis on your machine (external)
module.exports = new Analysis(writeFileTest, {
token: “xxxx”
});

=== EXCEPTION ===
…/Analysis/node_modules/@tago-io/sdk/out/modules/Account/Files.js:238
throw new Error(Could not upload part number ${partNumber}: ${ex.message});
^

Error: Could not upload part number 1: undefined
at Files._addToQueue (…/Analysis/node_modules/@tago-io/sdk/out/modules/Account/Files.js:238:27)

Hi Gary,

It may be a problem on the SDK. It seems to be correct to me.

I will check internally and provide you an status on that.

-Guilherme

Hi Gary,

That problem you’ve pointed out end up to be a bug. Good news is that our team has already fixed it. Your code is correct and should be working. (It has worked on a test I’ve performed)

-Guilherme

Thanks for the quick patch Guilherme.
I’ll test it tomorrow

Hi Guilherme,

I tried this again after updating the node packages. This now works when running externally, but fails to create the test2.txt file when running on the internal the Tago IO Analysis screen. Was the fixed code pushed out to the production system?

Hi Gary,

sorry, its still not updated in production, I will keep you updated here but I dont promise anything before next week, we’re adding new features to analysis and that fix should be included on the next release.

-Guillherme

No problem - we can run this externally for now.

1 Like