Skip to content

Instantly share code, notes, and snippets.

@kabeer11000
Created June 9, 2020 09:57
Show Gist options
  • Save kabeer11000/234bba56d529a272ec4ec8382d725a59 to your computer and use it in GitHub Desktop.
Save kabeer11000/234bba56d529a272ec4ec8382d725a59 to your computer and use it in GitHub Desktop.
//------JAVASCRIPT EXAMPLE--------//
/* MAIN FUNCTION TO UPLOAD STRING AS TEXT FILE TO SERVER */
function UploadFile(data, folderid)
{
var formData = new FormData();
//File Mime Type
var blob = new Blob([data], { type: 'plain/text' });
//*IMPORTANT*. Kabeers Drive will only accept if paramenter name is 'file[]' (Array)
formData.append('file[]', blob,'temp.txt');
var request = new XMLHttpRequest();
request.open('POST', "http://drive.hosted-kabeersnetwork.unaux.com/server/api/upload/index.php?id=" + folderid);
request.send(formData);
request.onreadystatechange = function (){
if (request.readyState == 4 && request.status == 200){
console.log("File uploaded!"+ this.response);
}
}
}
var userid = auth();
var text = 'Hello World';
//UserID is same as users "My Drive (Root)" folder Id
UploadFile(text, userid);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment