Details
-
Technical task
-
Resolution: Unresolved
-
Not Evaluated
-
None
-
None
-
None
Description
Drag and drop of files is supported by the web platform, however the behavior is different than from desktop platforms in some aspects.
Qt on desktop platforms: dropping files results in drop events with the mime type “text/uri-list”, where the data is a list of file:/// urls to the files.
Web Platform: dropping files results in drop events with a files array populated with JS File objects. File can be used to read file data asynchronously - see https://developer.mozilla.org/en-US/docs/Web/API/File.
Qt for WebAssembly: Currently, results are mixed: dropping an image file gives us the image (with mime type “application/x-qt-image”). Dropping an unknown file type does not work as well: the mime type is empty, and we don't get the full file data.
We should try to unify behavior across all platforms, if possible. The issue here is similar to the file dialog issue with Qt Quick: Users of the FileDialog class expects an URL, while the native API provides Qt with a File object. (both can be used to read the file contents, but they are not interchangeable)
Possible solution: Implement a custom file engine
- Can be read-only and immutable, with file content populated in advance. This enables usage from synchronous API (such as QFile).
- Applications get file urls or paths with a custom schema which causes QFile to read from the custom file engine.
- Optionally make use of asyncify to stream file content from the async File API.
- Memory optimization: hold file data in as JS ArrayBuffer objects, copy into heap memory on demand.