Kabeers Drive Upload API


After user has Signed into their Kabeers Drive Account access their files and folders with This API
The first example shows uploading files with regular Javascript. The second example shows uploading files with JQuery.




Authorization Function
Authorize A new Kabeers Drive Session.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script> //Run Auth Once Each Session if (!sessionStorage.auth) { auth(); sessionStorage.auth = "true"; } //------AUTHORIZATION--------// function auth() { var USERNAME = "KABEERS DRIVE USERNAME"; var PASSWORD = "KABEERS DRIVE PASSWORD"; $.ajax( { type: "GET", url: "http://drive.hosted-kabeersnetwork.unaux.com/server/api/login.php", dataType: 'json', headers: { "Authorization": "Basic " + btoa(USERNAME + ":" + PASSWORD) }, data: '', success: function (data) { sessionStorage.auth = "true"; return data.id; } }); } </script>

Uploading file in JQuery
Saving String as a text file to Kabeers Drive

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script> //------JQUERY EXAMPLE--------// function UploadFile(data, folderid) { var returndata; // Define a boundary, I stole this from IE but you can use any string AFAIK var boundary = "---------------------------7da24f2e50046"; var body = '--' + boundary + '\r\n' // Parameter name is "file" and local filename is "temp.txt" + 'Content-Disposition: form-data; name="file[]";' + 'filename="temp.txt"\r\n' // Add the file's mime-type + 'Content-type: plain/text\r\n\r\n' // Add your data: + data + '\r\n' + '--' + boundary + '--'; $.ajax( { contentType: "multipart/form-data; boundary=" + boundary, data: body, type: "POST", url: "http://drive.hosted-kabeersnetwork.unaux.com/server/api/upload/index.php?id=" + folderid, success: function (data, status) { console.log("File uploaded!"); console.log('Name: ' +data.name+ ' Data-ID : '+ data.id+ ' Status : '+ status); } }); } var userid = auth(); var text = 'Hello World'; //UserID is same as users "My Drive (Root)" folder Id UploadFile(text, userid); </script>

Uploading file in Vanilla JS
Saving String as a text file to Kabeers Drive

<script> //------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); </script>


This is a sample on how you can implement uploading string as a file from inside your App.
The response will look the same for uploading any file.


Example Response


On Success

{
   "name":"temp.txt",
   "id":"465d2cd6841195e9c905482818b09345",
   "size":"64604",
   "path":"http://drive.hosted-kabeersnetwork.unaux.com/user-files/7aa7d5d26ad72bfe4b1401f933293c7646d02cd6841195e9c905482818b09345.png",
   "shared":"0",
   "mime":"text/plain",
   "owner":"test",
   "dateCreated":"2020-05-31 23:09:45.087707",
   "dateModified":"2020-05-31 23:15:18.150134"
}

On Failure

{
   "upload":"failed"
}



Response Details

name id size path shared mime owner dateCreated dateModified
1 Defines the name of the File.
Can Be Changed.
Unique id of current file.
Every File has an uneditable id.
Size of current file. Where this file been stored on Kabeers Network Servers. If the file has link sharing enabled.
0 if file isn't shared & 1 if shared.
Mime Type of this file. Owner of this file.
Account used to upload this file.
When this file was created or uploaded.
Remains same.
When actions e.g. renaming was done on this file.
Can Be Changed based on user actions.




For More info Contact us at Kabeer11000@gmail.com.

© 2020 Kabeers Network | All Rights Reserved
Free Web Hosting