Open
Description
Bug Report
Capacitor Version
Latest Dependencies:
@capacitor/cli: 2.4.0
@capacitor/core: 2.4.0
@capacitor/android: 2.4.0
@capacitor/electron: 2.4.0
@capacitor/ios: 2.4.0
Installed Dependencies:
@capacitor/android not installed
@capacitor/ios not installed
@capacitor/cli 2.4.0
@capacitor/core 2.4.0
@capacitor/electron not installed
Platform(s)
Web.
Current Behavior
I followed the sample in the documentation. However, the converted path does not work on the browser showing GET http://localhost:8100/DATA/demo 404 (Not Found)
.
Expected Behavior
The image should be loaded with the provided path.
Code Reproduction
The minimal sample Ionic project can be found in this repository.
A tiny image is hard-coded as base64 string in the data
field when writing the file with Capacitor Filesystem
API.
const writeResult = await Filesystem.writeFile({
data: 'iVBORw0KGgoAAAANSUhEUgAAAAYAAAAECAYAAACtBE5DAAAABHNCSVQICAgIfAhkiAAAABl0RVh0U29mdHdhcmUAZ25vbWUtc2NyZWVuc2hvdO8Dvz4AAAA9aVRYdENyZWF0aW9uIFRpbWUAAAAAADIwMjDlubTlhavmnIgzMeaXpSAo6YCx5LiAKSAyM+aZgjI35YiGMjTnp5IACi9UAAAASElEQVQImWOUk5P7z4AFsEAoSQa/kGYGu2ezGbazuzP4K8jBJBgYGBjYGETVwxiszi9gaDp0A1mCgYHh7U6G6RcuM7xhYGAAAEFTDx/VUsAUAAAAAElFTkSuQmCC',
directory: FilesystemDirectory.Data,
path: 'demo',
recursive: true
});
this.src = Capacitor.convertFileSrc(writeResult.uri);
const readResult = await Filesystem.readFile({
directory: FilesystemDirectory.Data,
path: 'demo'
});
this.base64Src = `data:image/png;base64,${readResult.data}`;
The template shows two identical images with different approach: by path and by base64 string.
<img [src]="src" />
<img [src]="base64Src" />
The first image throws a 404 error.
Other Technical Details
npm --version
output: 6.14.8
node --version
output: v10.16.0
Other dependencies can be found in the sample project.