Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi,
I'm trying to upload a file to the default content library using the qrs api, in node.js
When I execute this code, I recieve a 201 code from the server, meaning the file has been created.
The file testDoc4.txt is created in the library.
I can access it via the URL
https://myHostName/content/Default/testDoc4.txt
But, this file is empty! I suppose I'm not giving the right externalpath.
My original testDoc4.txt file is on the server, on this path : C:\Qlik\server\shared\StaticContent
Could you please help me to find the well-formated externalpath?
Many thanks
var https = require('https');
var fs = require('fs');
var options = {
hostname: 'myHostName',
port: 4242,
path: '/qrs/contentlibrary/Default/uploadfile?externalpath=testDoc4.txt&overwrite=true&xrfkey=abcdefghijklmnop',
method: 'POST',
headers: {
'x-qlik-xrfkey' : 'abcdefghijklmnop',
'X-Qlik-User' : 'UserDirectory= Internal; UserId= sa_repository ',
'Content-Type' : 'text/html; charset=utf-8'
},
key: fs.readFileSync("C:\\javaTicket\\pem\\client_key.pem"),
cert: fs.readFileSync("C:\\javaTicket\\pem\\client.pem"),
ca: fs.readFileSync("C:\\javaTicket\\pem\\root.pem")
};
https.get(options, function(res) {
console.log("Got response: " + res.statusCode);
res.on("data", function(chunk) {
console.log("BODY: " + chunk);
});
}).on('error', function(e) {
console.log("Got error: " + e.message);
});
Hey Florian,
I can't claim to be any good at NodeJS, but this is running clean:
var fs = require('fs');
var request = require('request');
fs.readFile('C:\\Scripts\\NodeJS\\foo.xml', function (err, data) {
if (err) return console.error(err);
options = {
method: 'POST',
headers: {
'x-qlik-xrfkey' : 'abcdefghijklmnop',
'X-Qlik-User' : 'UserDirectory= Internal; UserId= sa_repository ',
'Content-Type' : 'application/xml'
},
key: fs.readFileSync('C:\\ProgramData\\Qlik\\Sense\\Repository\\Exported Certificates\\.Local Certificates\\client_key.pem'),
cert: fs.readFileSync("C:\\ProgramData\\Qlik\\Sense\\Repository\\Exported Certificates\\.Local Certificates\\client.pem"),
ca: fs.readFileSync("C:\\ProgramData\\Qlik\\Sense\\Repository\\Exported Certificates\\.Local Certificates\\root.pem"),
body: data
}
request.post(options, function (err, message, data) {
if (err) return console.error(err);
console.log(data)
});
});
The crux of the issue is that you're not including any actual reading / storing of the file that you want to send.
Hope that helps.