Google Drive file system provider
29 Nov 20242 minutes to read
The Google Drive file system provider allows the users to manage the files and folders in a Google Drive account. The Google Drive file system provider works on id basis where each file and folder have a unique ID. To get started, clone the EJ2.ASP.NET Core Google Drive File Provider using the following command.
git clone https://github.com/SyncfusionExamples/ej2-google-drive-aspcore-file-provider ej2-google-drive-aspcore-file-provider
cd ej2-google-drive-aspcore-file-provider
Google Drive file system provider use the Google Drive APIs to read the file in the file system and uses the OAuth 2.0 protocol for authentication and authorization. To authenticate from the client end, have to obtain OAuth 2.0 client credentials from the Google API Console
. To learn more about generating the client credentials from the from Google API Console, refer to this link.
After generating the client secret data, copy the JSON data to the following specified JSON files in the cloned location.
- EJ2FileManagerService > credentials > client_secret.json
- GoogleOAuth2.0Base > credentials > client_secret.json
After updating the credentials, just build and run the project. Now, the project will be hosted in http://localhost:{port}
, and it will ask to log on to the Gmail account for which created the client secret credentials. Then, provide permission to access the Google Drive files by clicking the allow access button in the page. Now, just mapping the ajaxSettings property of the FileManager component to the appropriate controller methods will allow to manage the files from the Google Drive.
@*Initializing File Manager with Google Drive file system service.*@
@* Replace the hosted port number in the place of "{port}" *@
<SfFileManager TValue="FileManagerDirectoryContent">
<FileManagerAjaxSettings Url="http://localhost:{port}/api/GoogleDriveProvider/GoogleDriveFileOperations"
UploadUrl="http://localhost:{port}/api/GoogleDriveProvider/GoogleDriveUpload"
DownloadUrl="http://localhost:{port}/api/GoogleDriveProvider/GoogleDriveDownload"
GetImageUrl="http://localhost:{port}/api/GoogleDriveProvider/GoogleDriveGetImage">
</FileManagerAjaxSettings>
</SfFileManager>
To perform file operations (Read, Create, Rename, Delete, Get file details, Search, Copy, Move, Upload, Download, GetImage) in the Syncfusion® Blazor File Manager component using the Google Drive file system provider, you need to initialize the Google Drive file system provider in the controller.
To initialize a local service with the above-mentioned file operations, create a new folder named Controllers
inside the server part of the project. Then, create a new file with the extension .cs
inside the Controllers folder and add the necessary file operations code available in the GoogleDriveProviderController.cs
found at this link. Additionally, you can check out all the necessary file operation method details for this provider in the same GitHub repository.
NOTE
To learn more about file actions that can be performed with Google drive file system provider, refer to this link