DEVELOPER CENTER
...
JavaScript
Libraries
$pinc
4min
the $pinc library gives you access to some common functions used across pathfix below are the list of common scenarios where you might use the library get the pathfix api call url or revoke url syntax $pinc getpathfixurl(providername, publickey, userid) $pinc getpathfixrevokeurl(providername, publickey, userid) remarks arguments description providername internal provider name see provider reference docid\ z26cdo6omb40w2fymu ut publickey optional defaults to the public key specified in the data public key docid\ ybjxrakfgeistdwi312ol attribute of the script tag userid optional defaults to the data user id docid\ six7fj9iqb5z2gv aa96r attribute of the script tag example //the code uses jquery function postmessage(){ //request pathfix to build the api call url var url = $pinc getpathfixurl("googlecalendar"); var pfxpayload = { "url" "https //www googleapis com/calendar/v3/users/me/calendarlist", "method" "get" } $post(url, json stringify(pfxpayload)) always(response=>{ console log(response); }) } function disconnect(){ //request pathfix to build the user disconnect/revoke authorization url var url = $pinc getpathfixrevokeurl("googlecalendar"); //no payload is needed $post(url) always(response=>{ console log(response); }) } read contents of a file before uploading to online storage syntax $pinc fileread(filereader, callback) returns {"type" "http mime type","content" "file content", uploadobject {}} remarks method call filereader required required , javascript filereader object javascript filereader object callback callback function reference return content the raw file content uploadobject pass as a parameter to the payload when uploading the file using pathfix passthrough endpoints docid\ mazd9101pgjpioxiazbkt example // fileinput is an html input element \<input type="file" id="myfileinput" multiple> var fileinput = document getelementbyid("myfileinput"); // files is a filelist object (similar to nodelist) var files = fileinput files; var file; // loop through files for (var i = 0; i < files length; i++) { // get item file = files item(i); //or file = files\[i]; //pathfix usage sample var pfxfile = $pinc fileread(file,response => { var pfxpayload = { "url" `https //storage googleapis com/upload/storage/v1/b/${options bucket}/o/`, "method" "post", "headers" { "x payload type" "file" }, "payload" response uploadobject } upload }); } extended code from developer mozilla org https //developer mozilla org/en us/docs/web/api/filelist