convertFileSrc
Module @netwiv/api/core · Kind Function
import { convertFileSrc } from '@netwiv/api/core';Convert a device file path to an URL that can be loaded by the webview.
Note that asset: and http://asset.localhost must be added to app.security.csp in tauri.conf.json.
Example CSP value: "csp": "default-src 'self' ipc: http://ipc.localhost; img-src 'self' asset: http://asset.localhost" to use the asset protocol on image sources.
Additionally, "enable" : "true" must be added to app.security.assetProtocol
in tauri.conf.json and its access scope must be defined on the scope array on the same assetProtocol object.
Signature
Section titled “Signature”function convertFileSrc(filePath: string, protocol?: string | undefined): stringExample
Section titled “Example”import { appDataDir, join } from '@netwiv/api/path';import { convertFileSrc } from '@netwiv/api/core';const appDataDirPath = await appDataDir();const filePath = await join(appDataDirPath, 'assets/video.mp4');const assetUrl = convertFileSrc(filePath);
const video = document.getElementById('my-video');const source = document.createElement('source');source.type = 'video/mp4';source.src = assetUrl;video.appendChild(source);video.load();Upstream since 1.0.0
Descriptions come from the pinned @tauri-apps/api@2.11.1 declarations (MIT OR Apache-2.0); imports are shown with @netwiv/api paths.