This post outlines two Webxdc APIs to export and import files or data. “files” in this sense may be any kind of binary blobs (this includes plain text files) that are identified by a name; this may or may not have a direct relation to the operating system’s file system.
This will enable webxdc-apps to eg.
- handle file formats typical to an app category - eg. an calendar could allow importing exiting .ics files - and could also exports its own state that way
- define their own file format to make migration easier and to allow a simple form of updates
- act as an data processor (eg. import a file, let it modify by the webxdc-app, export the file
Existing APIs: Currently, webxdc-apps can export/import data only by sending/receiving updates to other peers.
Scope of the new APIs: Exporting/Importing any blob to/from a local File object. Using files as additional storage or having permanent access to them is out of scope of the planned APIs.
Dealing with files do not always offer a great UX across platforms and also sometimes not even on a single device. Therefore, the API and the integration is designed closer to the chat/message metaphers that are already in use anyway.
webxdc.export()
promise = window.webxdc.export({file: File, text: "This file contains …"})
-
file
is a js File object containing a Blob and a name -
text
is any message that should be shown beside the exported file - returns a promise that is resolved to
true
once export is completed orfalse
on error/abort
It is up to the UI where to store the file, it should not be sent out to other users, however (this may come in the future).
Concrete implementation plans for Delta Chat is to write the file to the “Saved Messages” chat - from where it can be handled as any other file and also easily being accessed for import
webxdc.import()
array = window.webxdc.importFiles(extensions)
-
extensions
array of extensions that may be shown to the user (details have to be figured out, i suggest to be close to what js is using here for their file selectord) - returns a promise with an with
File
objects (same as the js file selector)
Concrete implentation plans for Delta Chat is to show sth. as the “All Media” view and let the user select a single file. the view is filtered by the extensions, however, with the option to access all files. later, this may be enhanced to multiple files.
Other implementations may just show the system’s file selector (which, depending on the system Delta Chat is running, may become and additional option to)
the goal of the API is also to make non-Delta-Chat-implemtations easy, so no part is bound to things only Delta Chat has, cc @singpolyma
ftr: corresponding github issue: Add import/export API to WebXDC · Issue #4350 · deltachat/deltachat-core-rust · GitHub