Skip to content

Commit aa83df7

Browse files
dasergerobpaveza
authored andcommitted
Added docs on CSP rules needed for using cdvfile in DOM src. This closes apache#120
1 parent fe3d6f4 commit aa83df7

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,10 +406,21 @@ which can be used to identify the file uniquely.
406406

407407
`cdvfile://localhost/persistent|temporary|another-fs-root*/path/to/file` can be used for platform-independent file paths.
408408
cdvfile paths are supported by core plugins - for example you can download an mp3 file to cdvfile-path via `cordova-plugin-file-transfer` and play it via `cordova-plugin-media`.
409-
To use `cdvfile` as a tag' `src` you should convert it to native path via `toURL()` method of the resolved fileEntry, which you can get via `resolveLocalFileSystemURL` - see examples below.
410409

411410
__*Note__: See [Where to Store Files](#where-to-store-files), [File System Layouts](#file-system-layouts) and [Configuring the Plugin](#configuring-the-plugin-optional) for more details about available fs roots.
412411

412+
To use `cdvfile` as a tag' `src` you can convert it to native path via `toURL()` method of the resolved fileEntry, which you can get via `resolveLocalFileSystemURL` - see examples below.
413+
414+
You can also use `cdvfile://` paths directly in the DOM, for example:
415+
```HTML
416+
<img src="cdvfile://localhost/persistent/img/logo.png" />
417+
```
418+
419+
__*Note__: This method requires following Content Security rules updates:
420+
* Add `cdvfile:` scheme to `Content-Security-Policy` meta tag of the index page, e.g.:
421+
- `<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: `**cdvfile:**` https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *">`
422+
* Add `<access origin="cdvfile://*" />` to `config.xml`.
423+
413424
**Converting cdvfile:// to native path**
414425

415426
```javascript

0 commit comments

Comments
 (0)