Hi Dandiebolt,
I have to read any type of file (i.e. PDF, ms office files) from my file system (windows server) and add them to file attachment field into a quickbase table.
I use javascript (node.js) to read a file with base64 encoding(as quickbase requires files to have base64 encoding) and use http post method (API_AddRecord) to upload the file. I have made the field as Mandatory (just to ensure the content is there).
I always get error that "Sorry, you didnot supply a value for the required field.... Please provide a non blank value".
I fail to understand that when my console.log is showing value (first line in uploadfiletoqb method), why API is complaining about the field being blank!
I feel I am wrong somewhere which i am not able to comprehend!
Can some one please please help !!!
Here is my code :
var http = require('https');var request = require('request'); // npm install requestvar fs = require("fs");var buf = new Buffer(1024);
console.log("Going to open an existing file");
var readStream = fs.createReadStream('d:\\MyData\\MyNode.js\\Certificates\\b.pdf',{ encoding: 'base64' });readStream.on('data', function (chunk) { buf += chunk; console.log("read data 11 "+buf.length);})readStream.on('end', function () { console.log("read data "+buf.length); uploadfiletoqb(buf);});
function uploadfiletoqb(buf1){ console.log("encoded file"+buf1); var xml = '<qdbapi><udata>mydata</udata><field fid="6" filename="b.pdf">'+buf1+'</field></qdbqpi>'; console.log("-----"); //console.log(xml); console.log("-----"); request({ url : "xxxx@yyyyy.com&password=xxxxx"" rel="nofollow">https://sssss.quickbase.com/db/bm3uve9ig?act=API_AddRecord&username=xxxx@yyyyy.com&password=...;, method: "POST", //headers: { //"content-type": "text/xml" //}, body:xml}, function (err, remoteResponse, remotebody){ if (err) {console.log("error"+remoteResponse+" -- "+err); } console.log("ok "+remoteResponse +" "+remotebody); }); }would appreciate help!!!!
thanks & regards
dinesh