The Google Drive Integration package provides you with the ability to easily manage files stored in Google Drive from a Wix site. You can perform the following actions with this package:
Before using the package, set up the following:
velo-google-drive-credentials
.https://drive.google.com/drive/u/0/folders/{YOUR_FOLDER_ID}
folderId
.The following backend files are included in the package. Note that only exported functions that you can use in your site are listed here.
Note: If you want to use the package in your page or site code, use a web module (.jsw) file instead of a backend (.js) file to avoid exposing the package functions to unauthorized visitors.
The code in this file contains functions for accessing and working with files in Google Drive from your site.
To use the functions below in your backend code, import them with the following syntax:
The file contains the following functions:
uploadFileByUrl()
Creates and uploads a file by specifying its URL and the Google Drive folder to upload to. The URL can be either an absolute https://
link or a link in the Velo URL format, such as: image://
, video://
, audio://
Syntax:
Parameters:
The ID of the file and a file
object containing options to use when uploading the file.
folderId:
String containing the ID of the shared folder to upload to. Required.options:
An object that contains file metadata needed to upload the file. Required.
url:
File URL. Required. Can be either an absolute https://
link or a link in the Velo URL format, such as: image://
, video://
, audio://
name?:
Optional file name.description?:
Optional file description.Returns:
A promise that, if successful, resolves to an object containing metadata of the uploaded file:
id:
String containing the ID of the uploaded file.kind:
String containing the kind of the uploaded file, typically the string drive#file
.mimeType:
String containing the mime type of the uploaded file, such as image/png
or image/jpeg
.name:
String containing the name of the uploaded file.Example:
getFileById()
Gets a file's metadata by specifying the file’s ID. You can choose which metadata fields to return.
Syntax:
Parameters:
fileId:
String containing the file ID. Required.fields?:
An optional string specifying the metadata fields to include in the returned object, in addition to the following default fields that are always returned: id
, name
, mimeType
, size
, createdTime
, and modifiedTime.
Separate the fields in the string with commas.Returns:
A promise that, if successful, resolves to an object containing metadata of the uploaded file. The fields returned are those specified using the fields
parameter.
Example:
deleteFileById()
Permanently deletes a file, bypassing the trash bin. If the file belongs to a shared drive, you must have organizer permissions for the parent-level folder. If deleting a folder, all child files that you own are also deleted.
Syntax:
Parameters:
fileId:
String containing the ID of the file you want to delete. Required.Returns:
A promise that, if successful, resolves to true
if the file is deleted successfully.
Example:
listFiles()
Gets the metadata of a list of files located in your Google Drive. You can set which files to list by sending a query as a string, and you can also set which metadata fields to return.
Note: The listFiles()
function lists files of all users, provided that they match the specified query. We advise you to return only relevant files/fields to the frontend.
Syntax:
Parameters:
query?:
An optional string containing a query for filtering the file metadata results. Query string examples
fields?:
An optional string specifying which metadata fields to include in the returned object, in addition to the following default fields that are always returned: id
, name
, mimeType
, size
, createdTime
, and modifiedTime.
Separate the fields in the string with commas.
Note: File properties are nested under files
, so when listing the field names, wrap them between the ( )
's of files
. See the example below.
Returns:
A promise that, if successful, resolves to an array of objects containing the metadata of the queried files, according to the specified fields.
Example:
createPermissions()
Creates a permission for a file. Permissions enable file/folder access to others. Access can be granted to a user, group, domain, or anyone else.
Parameters:
The ID of the file and an object with permission options.
fileId:
String containing the ID of the file you want to set permissions for. Required.permissionInfo
: Object containing the information needed to create the permission. Required.
role:
The role granted by this permission. Required. One of: owner, organizer, fileOrganizer, writer, commenter, reader
type:
Who is being granted the permission. Required. One of: user, group, domain, anyone
domain?:
If type
is domain
, a string containing the domain being granted the permission. Otherwise, optional.Returns:
A promise that, if successful, resolves to an object defining the permission that was created for the file:
id:
String containing the ID of the file you set permissions for.kind:
String containing the resource kind, typically the string "drive#file"
.role:
String containing the role granted by this permission. One of: owner, organizer, fileOrganizer, writer, commenter, reader
type:
String containing who is being granted the permission. One of: user, group, domain, anyone
allowFileDiscovery:
Boolean indicating whether the file is discoverable.Example:
This Velo package uses the following npm package. To view the npm license, see the npm readme.
1.0 Initial version.
google, googleapis, drive