upload file to google drive using javascript

Overview

Google Drive JQuery plugin

This JQuery plugin helps to rapidly connect and utilize Google Drive storage for any authenticated account.

Usage

GDrive plugin has authentication/authorization functions to whatsoever Google drive account. Once eastablished, the connectedness allows a javascript application to manage binder and files on the account.

Requirements

The plugin has no dependency but http://apis.google.com/js/client.js which is loadeded automaticaly past the plugin.


Setup

Include this markup in client page:

                      <html> </head> <script type="text/javascript" src="scripts/jquery.gdrive-one.0.0.js"></script> </caput> <body> <button id="apiDriveAuthenticate" blazon="submit">Start Google Drive Hallmark</button> <div id="gDriveAuthorization"></div> </body> </html>                  

The authentication process for accessing Google Bulldoze is triggered by a customer via a submit button. Note that presented ClientID and KeyAPi are dummy keys. Create y'all own account on console.developers.google.com and obtain yours ClientID and KeyAPi keys. To undestand and select the right hallmark scope visit this link. This is reqiured javascript code to initialize the plugin:

                      //gdrive options with authentication and dominance level requested var gdrive_pluginOptions = {     authentication: {         clientID: "209560473815-yourkey.apps.googleusercontent.com",         keyAPI: "YOURAPIKEY"     },     scopes: ["https://world wide web.googleapis.com/auth/drive", "https://www.googleapis.com/auth/bulldoze.file","https://www.googleapis.com/auth/userinfo.email"] }  //initialize gdrive $(part () {     //initialize     $("#apiDriveAuthenticate").gDrive(gdrive_pluginOptions);     //listen to the event     $('body').demark('DrivePlugin_loaded',    part (eastward, information) {             	var auth = $.gDrive.authorized();     	if (auth) {         	$("#apiDriveAuthenticate").hibernate();         	$("#gDriveAuthorization").css("color", "green");         	$("#gDriveAuthorization").text("Authorized");     	}     	else {         	$("#gDriveAuthorization").css("colour", "orange");         	$("#gDriveAuthorization").text("Not Authorized");     	}     });  });                  

API reference

This tabular array presents public API for the plugin.

$.gDrive.folder.create

A part to create folder in parents folder IDs (assortment) parentIds with title and description. Set a flag uniqueTitle to create a binder simply if a folder does non exist with the same name.

                                  $.gDrive.folder.create(title, parentIds, folderColorRgb, description, uniqueTitle, callback);                              

The callback parameter is required to ready synchronous operations to process returned value subsequently the phone call completion.

                                  $.gDrive.binder.create(title, parentIds, folderColorRgb, description, uniqueTitle, function(outcome) {  	$.each(result,function(index,value){ alert(value.id+"-"+value.championship+"-"+value.createdDate)});  });                              

$.gDrive.folder.getChildren

A office to become list of folders in parent folder ID folderId.

                                  $.gDrive.folder.getChildren(folderId, callback);                              

The callback parameter is required to set synchronous operations to procedure returned value later on the phone call completion.

                                  $.gDrive.folder.getListFolders(folderId, part(effect) {  	$.each(outcome,office(index,value){ alert(value.id+"-"+value.title+"-"+value.createdDate)});  });                              

$.gDrive.binder.getByTitle

A function to discover binder by binder proper noun championship. Set up includeTrashed parameter as true, false or goose egg for but trashed.

                                  $.gDrive.binder.getByTitle(title, includeTrashed, callback);                              

The callback parameter is required to gear up synchronous operations to process returned value after the call completion. Array of binder ids with the same title is returned.

                                  $.gDrive.folder.getByTitle(title, includeTrashed, office(event) {  	$.each(result,function(alphabetize,value){ warning(value.id) });  });                              

$.gDrive.binder.remove

A office to remove folder with id.

                                  $.gDrive.binder.remove(id, callback);                              

The callback parameter is required to set synchronous operations to process returned value after the telephone call completion. True or false is returned.

                                  $.gDrive.binder.remove(id, part(result) {  	alert(result)  );  });                              

$.gDrive.file.go

A function to get listing of files in parent folder ID folderId. Set includeTrashed parameter every bit true, fake or null for only trashed.

                                  $.gDrive.file.become(folderId, includeTrashed, callback);                              

The callback parameter is required to set synchronous operations to process returned value after the phone call completion.

                                  $.gDrive.file.get(folderId, includeTrashed, function(issue) {  	$.each(result,role(index,value){ alert(value.id+"-"+value.title+"-"+value.createdDate)});  });                              

$.gDrive.file.existInFolder

A part to get information if file fileId exists in binder ID folderId.

                                  $.gDrive.file.existInFolder(folderId, fileId, callback);                              

The callback parameter is required to prepare synchronous operations to process returned value later the telephone call completion.

                                  $.gDrive.file.existInFolder(folderId, fileId, office(result) {  	$.each(result,part(index,value){ alert(value==true)});  });                              

$.gDrive.file.removeFromFolder

A function to remove file fileId from folder ID folderId.

                                  $.gDrive.file.getListFiles(folderId, fileId, callback);                              

The callback parameter is required to set synchronous operations to procedure returned value afterwards the call completion.

                                  $.gDrive.file.removeFromFolder(folderId, fileId, function(result) {  	$.each(result,function(alphabetize,value){ alert(value==true)});  });                              

$.gDrive.file.trash

A part to trash file fileId.

                                  $.gDrive.file.trash(fileId, callback);                              

The callback parameter is required to set synchronous operations to process returned value later on the telephone call completion.

                                  $.gDrive.file.trash(folderId, fileId, function(result) {  	$.each(result,function(index,value){ alert(value==true)});  });                              

$.gDrive.file.remove

A function to remove file fileId.

                                  $.gDrive.file.remove(fileId, callback);                              

The callback parameter is required to fix synchronous operations to procedure returned value after the call completion.

                                  $.gDrive.file.remove(folderId, fileId, part(issue) {  	$.each(issue,function(index,value){ alert(value==truthful)});  });                              

$.gDrive.file.upload

A function to upload file fileData from browser upload function with description to parent binder folderID .

                                  $.gDrive.file.upload(fileData, folderID, description, callback);                              

The callback parameter is required to set synchronous operations to process returned value after the telephone call completion.

                                  $.gDrive.file.upload(fileData, folderID, clarification, office(file) {  	$.each(consequence,function(index,value){ alarm(value.id+"-"+value.title+"-"+value.createdDate) });  });                              

$.gDrive.file.uploadStringAsFile

A part to upload file serialized as string fileContent to parent folder folderID with mimeType and clarification.

                                  $.gDrive.file.uploadStringAsFile(fileContent, folderID, fileName, mimeType, description, callback);                              

The callback parameter is required to gear up synchronous operations to process returned value after the call completion.

                                  $.gDrive.file.uploadStringAsFile(fileContent, folderID, fileName, mimeType, description, function(result) {  	$.each(issue,function(index,value){ warning(value.id+"-"+value.championship+"-"+value.createdDate) });  });                              

$.gDrive.file.getContent

A function to get file fileId content.

                                  $.gDrive.file.getContent(fileId, callback);                              

The callback parameter is required to ready synchronous operations to process returned value later the call completion.

                                  $.gDrive.file.getContent(fileId, office(event) {  	$.each(result,role(index,value){ alert(value.toString()) });  });                              

$.gDrive.file.downloadAction

A office to become file fileId url link for download.

                                  $.gDrive.file.downloadAction(fileId, callback);                              

The callback parameter is required to prepare synchronous operations to process returned value afterward the phone call completion.

                                  $.gDrive.file.downloadAction(fileId, office(outcome) {  	$.each(outcome,function(index,value){ alert(value.toString()) });  });                              

$.gDrive.revokeAuthorization

A part to revoke dominance.

                                  $.gDrive.revokeAuthorization();                              

The callback parameter is required to set up synchronous operations to procedure returned value after the telephone call completion.

                                  $.gDrive.revokeAuthorization( function(result) {  	 alert(consequence.toString());  });                              

Events

DrivePlugin_loaded event is fired after the plugin is loaded.

                      $('torso').bind('DrivePlugin_loaded',        function (due east, information) {                     //is it authorized?     	    var auth = $.gDrive.authorized();         });                  

Properties

These are public properties (read-only) for the plugin.

  • $.gDrive.authorized() Gets information if plugin is authorized.
  • $.gDrive.isPluginLoaded() Gets information if plugin is loaded.
  • $.gDrive.isClientAPILoaded() Gets data if customer API is loaded.
  • $.gDrive.userEmail() Gets user email account used for authenticated account.
  • $.gDrive.userEmailPicture() Gets user account motion picture for authenticated account.

Download

Version ane.two.0 - Nov 2, 2015

  • NEW Added qunit tests project.

Download plugin minimized source


Version 1.1.0 - October 15, 2015

  • NEW Revoking Google account authentication characteristic.
  • FIXED Issue with updating file.
  • UPDATED Uploading string content.

Version i.0.0 - Sep 2, 2015

  • DEFAULT First version.

Your Back up

For additional plugin customization, you can become uncompressed code with qunit tests solution for a minimal cost of $20CAD.

Contact us

If take questions, write us an email to plugins@anasoft.net.

Thanks.

coleuptarterxed.blogspot.com

Source: https://www.anasoft.net/assets/portfolio/gdrive.html

0 Response to "upload file to google drive using javascript"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel