Discussions

Expand all | Collapse all

Upload file in File Attachment field using add record fail

  • 1.  Upload file in File Attachment field using add record fail

    Posted 09-09-2017 11:04
    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 request
    var 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


  • 2.  RE: Upload file in File Attachment field using add record fail

    Posted 09-11-2017 03:11
    This might seem silly, but are there any fields on the table that are "required" at the field level?  That is what your error is...  
    "Sorry, you did not supply a value for the required field.... Please provide a non blank value


  • 3.  RE: Upload file in File Attachment field using add record fail

    Posted 09-11-2017 09:30
    Hi Matthew

    Thanks for the revert. My issue is not that ... as I have tested it by removing mandatory setting also, but it still doesn't work. The xml content is simply not send to the quickbase. I did simple tests to determinde that.

    The issue as per me is that how do i post a http request (since I am running from outside quickbase) for adding a record and uploading a attachment field. 

    Can you help me over there ?

    My code looks like this :-

    var vxml = '<qdbapi><udata>mydata</udata><usertoken>token<\usertoken><field name="Upload" filename="b.pdf">'+buf1+'</field></qdbqpi>';

    request({
            url : "https://apollotyres.quickbase.com";,
            path: "/db/bm3uve9ig",
            method: "POST", 
            headers: {
                                  "content-type": "text/xml" ,
                                  "QUICKBASE-ACTION": "API_AddRecord"
                       }, 
           data:vxml
    }, function (err, remoteResponse, remotebody){
    if (err) {console.log("error"+remoteResponse+" -- "+err); }
        console.log("error "+remoteResponse +" "+remotebody);
    });


    Please note buf1 in first line of code where i have declared the XML variable is a base64 encoded content of a PDF file which i am trying to upload.  I am aware how to add a record by passing all parameters data through URL, but unable to do so by passing the XML as data in request.

    Hope you can guide me.

    regards
    dinesh