Writing Files to Tago

Writing Files to Tago

@Gary Howell

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("/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//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//sdk/out/modules/Account/Files.js:238:27)