ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

New WINDEV, WEBDEV and WINDEV Mobile 2024 feature!
Help / WLanguage / WLanguage functions / Communication / Drive functions
  • Overview
  • Prerequisite
  • How to?
  • Authentication
  • Manipulating drive files and directories
  • Special case: manipulating files in Google Docs Editors
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
Others
Stored procedures
Overview
There are many online storage services available. WINDEV, WEBDEV and WINDEV Mobile allow you to easily manipulate files on Dropbox, Google Drive and OneDrive. The code is the same regardless of the storage service used.
In Google Drive, you can also manipulate files from Google Docs Editors.
Prerequisite
To manipulate files, you need to configure the drives you want to use. For more details, see Prerequisites for using Google Drive, OneDrive and Dropbox.
How to?

Authentication

The use of these storage services requires authentication.
You can access the different services using OAuth 2.0.
To do so:
  1. Create a new OAuth2Parameters variable.
  2. Define the various properties of this variable, including:
    • ClientID: Client ID obtained when configuring the drive.
    • ClientSecret: Secret identifier obtained when configuring the drive.
      iPhone/iPad There is no secret identifier in iOS.
    • RedirectionURL: Specify the desired URL, e.g. "http://localhost:29000".
      iPhone/iPad For iOS, the redirect URL corresponds to the "iOS URL scheme" provided by Google during the configuration process. The redirection URL should have the following format: "com.googleusercontent.apps.123-abc:/oauth".
  3. Create a variable of type Drive, and use the connection function for the desired service:
    New in version 2024
    dpDriveConnect
    Creates a connection to Dropbox.
    New in version 2024
    GglDriveConnect
    Creates a connection to Google Drive.
    New in version 2024
    oDriveConnect
    Creates a connection to OneDrive.
Remark: It is also possible to pass a token with a refresh token. This solution avoids asking the user for login details again. The information to be used is detailed in the documentation of each connection function.
Examples:
  • Authenticating to Google Drive using the OAuth 2.0 protocol:
    // Authenticating to Google Drive using the OAuth 2.0 protocol
    oOAuth2Param is OAuth2Parameters
    oOAuth2Param.ClientID = "client_id"
    oOAuth2Param.ClientSecret = "client_secret"
    oOAuth2Param.RedirectionURL = "http://localhost:9000/"
     
    MyDrive is gglDrive
    MyDrive = GglDriveConnect(oOAuth2Param)
  • Authenticating to Google Drive using a token:
    // Authenticating to Google Drive using a token (refresh token)
    oOAuth2Param is OAuth2Parameters
    oOAuth2Param is OAuth2Parameters
    oOAuth2Param.ClientID = "client_id"
    oOAuth2Param.ClientSecret = "client_secret"
    oOAuth2Param.RedirectionURL = "http://localhost:9000/"

    oOAuth2Token is AuthToken
    oOAuth2Token = AuthIdentify(oOAuth2Param)
     
    MyDrive is gglDrive
    MyDrive = GglDriveConnect(oOAuth2Token)

Manipulating drive files and directories

The following functions are used to manipulate files and directories on a drive. All these functions use the Drive variable, which is specified during the authentication.
  • File manipulation functions:
    New in version 2024
    DriveCopyFile
    Copies a single file on a remote drive to another directory on same drive.
    New in version 2024
    DriveCreateFile
    Creates a file on the remote drive.
    New in version 2024
    DriveDeleteFile
    Deletes a file from a remote drive.
    New in version 2024
    DriveDownloadFile
    Downloads a file from a remote drive to the user's computer.
    New in version 2024
    DriveListFile
    Lists the files in a cloud-based drive directory.
    New in version 2024
    DriveMoveFile
    Moves a file on a remote drive from one directory to another.
    New in version 2024
    DriveRename
    Renames a file or directory on a remote drive.
    New in version 2024
    DriveUploadFile
    Uploads a local file to a remote drive.
  • Directory manipulation functions:
    New in version 2024
    DriveCopyDirectory
    Copies a directory on a remote drive to another directory.
    New in version 2024
    DriveCreateDirectory
    Creates a directory on the remote drive.
    New in version 2024
    DriveDeleteDirectory
    Deletes a directory and its files from a remote drive.
    New in version 2024
    DriveDownloadDirectory
    Downloads a directory and its files from a remote drive to the user's computer.
    New in version 2024
    DriveListDirectory
    Lists drive directories.
    New in version 2024
    DriveMoveDirectory
    Moves a directory and its contents to another directory within a remote drive.
    New in version 2024
    DriveRename
    Renames a file or directory on a remote drive.
    New in version 2024
    DriveUploadDirectory
    Uploads a directory and its contents to a remote drive.

Special case: manipulating files in Google Docs Editors

Google Drive allows users to manipulate files using the Google Docs Editors: Docs, Sheets, Slides, etc.
These files must be manipulated using:
  • a variable of type gglDrive, which is the result of the GglDriveConnect function.
  • a variable of type GglFile, which allows you to manipulate files in the Google Docs Editors.
There are two specific functions for manipulating these files:
New in version 2024
DriveDownloadGglFile
Downloads a Google Docs Editors file from Google Drive in a given compatible format.
New in version 2024
DriveListFileGgl
Lists Google Docs Editors files (Docs, Sheets, etc.) present on Google Drive.
DriveListFileGgl gets the list of Google Docs Editors files on the drive. This function initializes the GglFile variable type. This variable type can then be used by the different Drive functions.
Example:
oOAuth2Param is OAuth2Parameters
oOAuth2Param.ClientID = "client_id"
oOAuth2Param.ClientSecret = "client_secret"
oOAuth2Param.RedirectionURL = "http://localhost:9000/"

gglMyDrive is gglDrive
gglMyDrive = GglDriveConnect(oOAuth2Param) 

arrGglFile is array of GglFile
arrGglFile = DriveListFileGgl(gglMyDrive, "/", frRecursive)

FOR EACH Queue OF arrGglFile
SWITCH Queue.MimeType
CASE mimeTypeGglDocs: Queue.ExportMimeType = mimeTypeDOCX
CASE mimeTypeGglSheets: Queue.ExportMimeType = mimeTypeXLSX
OTHER CASE: Queue.ExportMimeType = mimeTypePDF
END 
let ResDownload = DriveDownloadGglFile(gglMyDrive, arrGglFile[1], "c:\MyDocuments")
IF ErrorOccurred THEN
// Error handling
Trace ("An error has occurred")
RETURN
END
END
Related Examples:
Drive functions Unit examples (WINDEV): Drive functions
[ + ] This example illustrates the use of Drive functions (Google Drive, Dropbox, OneDrive).
Drive functions Unit examples (WINDEV Mobile): Drive functions
[ + ] This example illustrates the use of Drive functions (Google Drive, Dropbox, OneDrive).
Minimum version required
  • Version 2024
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 01/10/2024

Send a report | Local help