Hi, I was wondering how to access the vRO getTempDirectory() equivalent while working with Python or NodeJS. Anyone has any idea on that or any workaround?
My end goal is to save a file that I am getting over GET and do a POST later.
NOTE: The marked correct answer is using the filesystem inside ZIP to read data and not write it, As it is read-only. That's the best i could find yet. Please let me know if you have some better ideas.
I guess I was too quick to write that in my last comment and definitely ignorant. In reality, it's half truth. You are right, this is not writable at all. The filesystem inside is read-only.
However, luckily that suited my case. I had to send a package over REST and that package is static. So, i did this and it worked for me.
exports.handler = (context, inputs) => {
const process = require('process');
const request = require('request');
const fs = require('fs');
process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = 0;
var options = {
'method': 'POST',
'url': 'https://vRO.fqdn/vco/api/packages',
'headers': {
'Accept': 'application/xml',
'Authorization': 'Basic eDIxMzgxNkB********DpNYXIjMjAyMw=='
},
formData: {
'file': {
'value': fs.createReadStream('com.mayank.emptyPackage.package'),
'options': {
'filename': 'com.mayank.emptyPackage.package',
'contentType': null
}
}
}
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});
}
inside the ZIP, I have added the package already and I am sending it over POST call.
I found a workaround. Instead of using Type=Script, use Type=Zip for Polyglot scripts (Python, NodeJS & PowerShell) and use the folder structure in that zip as your playground.
Hello Mayank,
very interesting approach, but in my case with Node,js it doesn't work. Can you publish your example please. Below my.
Thanks and best regards
Stefan
exports.handler = (context, inputs, callback) => {
//console.log('Inputs were ' + JSON.stringify(inputs));
try {
var fs = require("fs");
fs.writeFileSync(__dirname + "/temp/helloWorld.txt", "Hello World");
var fileContent = fs.readFileSync(__dirname + "/temp/helloWorld.txt", "utf8");
console.log(fileContent);
} catch(exception) {
console.log("An error occurred");
console.log(exception);
}
callback(undefined, {status: "done"});
}
I guess I was too quick to write that in my last comment and definitely ignorant. In reality, it's half truth. You are right, this is not writable at all. The filesystem inside is read-only.
However, luckily that suited my case. I had to send a package over REST and that package is static. So, i did this and it worked for me.
exports.handler = (context, inputs) => {
const process = require('process');
const request = require('request');
const fs = require('fs');
process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = 0;
var options = {
'method': 'POST',
'url': 'https://vRO.fqdn/vco/api/packages',
'headers': {
'Accept': 'application/xml',
'Authorization': 'Basic eDIxMzgxNkB********DpNYXIjMjAyMw=='
},
formData: {
'file': {
'value': fs.createReadStream('com.mayank.emptyPackage.package'),
'options': {
'filename': 'com.mayank.emptyPackage.package',
'contentType': null
}
}
}
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});
}
inside the ZIP, I have added the package already and I am sending it over POST call.
Hello Mayank,
thank you very much for sharing your source.
Best regards
Stefan