aWhere Manual
DevelopWidgets

Data import

Imports the collections of a file in Drive into a database, and tells your page with the message import when one is done.

The data-import widget imports the collections of a file in Drive into a database, one collection at a time, and shows the progress.

URL and parameters

The widget is at <site>/widgets/data-import. The parameters every widget takes are in Widgets.

ParameterMeaningRequired
source_item_idThe _id of the file that holds the collections. Without it, the user picks one in the widget.No
target_item_idThe _id of the database to import into. Without it, the user picks one in the widget.No

Messages

actionDirectionpayload
importwidget to your page{ parent }, where parent is the _id of the target database. Sent once per collection, when that collection reaches 100%.
cancelwidget to your pageNone. The user closed the widget.

This widget does not send ready and does not read post-widget-parameters. It sends error and close-with-error as in Widgets.

Example

embedParams is the common parameters from Widgets.

const params = new URLSearchParams({
  ...embedParams,
  source_item_id: fileId,
  target_item_id: databaseId,
})
frame.src = `${site}/widgets/data-import?${params}`

addEventListener('message', (e) => {
  if (e.origin !== site || e.data.messageToken !== messageToken) return
  if (e.data.action === 'import') refreshTables(e.data.payload.parent)
  if (e.data.action === 'cancel') frame.remove()
})

Notes

import arrives once per collection, not once per file, and the widget does not close itself. The user can import the next collection until you close the widget.

On this page