Skip to content

Commit c4b3fb0

Browse files
committed
docs(tutorial): update react and vue readFile cpde
1 parent 8ea7d49 commit c4b3fb0

4 files changed

Lines changed: 28 additions & 28 deletions

File tree

docs/react/your-first-app/4-loading-photos.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,11 @@ export function usePhotoGallery() {
106106

107107
// CHANGE: Display the photo by reading into base64 format
108108
for (const photo of photosInPreferences) {
109-
const readFile = await Filesystem.readFile({
109+
const file = await Filesystem.readFile({
110110
path: photo.filepath,
111111
directory: Directory.Data,
112112
});
113-
photo.webviewPath = `data:image/jpeg;base64,${readFile.data}`;
113+
photo.webviewPath = `data:image/jpeg;base64,${file.data}`;
114114
}
115115

116116
setPhotos(photosInPreferences);
@@ -143,11 +143,11 @@ export function usePhotoGallery() {
143143
const photosInPreferences = (photoList ? JSON.parse(photoList) : []) as UserPhoto[];
144144

145145
for (const photo of photosInPreferences) {
146-
const readFile = await Filesystem.readFile({
146+
const file = await Filesystem.readFile({
147147
path: photo.filepath,
148148
directory: Directory.Data,
149149
});
150-
photo.webviewPath = `data:image/jpeg;base64,${readFile.data}`;
150+
photo.webviewPath = `data:image/jpeg;base64,${file.data}`;
151151
}
152152

153153
setPhotos(photosInPreferences);

docs/react/your-first-app/5-adding-mobile.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ const savePicture = async (photo: Photo, fileName: string): Promise<UserPhoto> =
4646
// CHANGE: Add platform check
4747
// "hybrid" will detect mobile - iOS or Android
4848
if (isPlatform('hybrid')) {
49-
const readFile = await Filesystem.readFile({
49+
const file = await Filesystem.readFile({
5050
path: photo.path!,
5151
});
52-
base64Data = readFile.data;
52+
base64Data = typeof file.data === 'string' ? file.data : await file.data.text();
5353
} else {
5454
// Fetch the photo, read as a blob, then convert to base64 format
5555
const response = await fetch(photo.webPath!);
@@ -93,11 +93,11 @@ const loadSaved = async () => {
9393
// If running on the web...
9494
if (!isPlatform('hybrid')) {
9595
for (const photo of photosInPreferences) {
96-
const readFile = await Filesystem.readFile({
96+
const file = await Filesystem.readFile({
9797
path: photo.filepath,
9898
directory: Directory.Data,
9999
});
100-
photo.webviewPath = `data:image/jpeg;base64,${readFile.data}`;
100+
photo.webviewPath = `data:image/jpeg;base64,${file.data}`;
101101
}
102102
}
103103

@@ -131,11 +131,11 @@ export function usePhotoGallery() {
131131
// If running on the web...
132132
if (!isPlatform('hybrid')) {
133133
for (const photo of photosInPreferences) {
134-
const readFile = await Filesystem.readFile({
134+
const file = await Filesystem.readFile({
135135
path: photo.filepath,
136136
directory: Directory.Data,
137137
});
138-
photo.webviewPath = `data:image/jpeg;base64,${readFile.data}`;
138+
photo.webviewPath = `data:image/jpeg;base64,${file.data}`;
139139
}
140140
}
141141

@@ -167,10 +167,10 @@ export function usePhotoGallery() {
167167
let base64Data: string | Blob;
168168
// "hybrid" will detect mobile - iOS or Android
169169
if (isPlatform('hybrid')) {
170-
const readFile = await Filesystem.readFile({
170+
const file = await Filesystem.readFile({
171171
path: photo.path!,
172172
});
173-
base64Data = readFile.data;
173+
base64Data = typeof file.data === 'string' ? file.data : await file.data.text();
174174
} else {
175175
// Fetch the photo, read as a blob, then convert to base64 format
176176
const response = await fetch(photo.webPath!);

docs/vue/your-first-app/4-loading-photos.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,11 @@ export const usePhotoGallery = () => {
117117

118118
// CHANGE: Display the photo by reading into base64 format
119119
for (const photo of photosInPreferences) {
120-
const readFile = await Filesystem.readFile({
120+
const file = await Filesystem.readFile({
121121
path: photo.filepath,
122122
directory: Directory.Data,
123123
});
124-
photo.webviewPath = `data:image/jpeg;base64,${readFile.data}`;
124+
photo.webviewPath = `data:image/jpeg;base64,${file.data}`;
125125
}
126126

127127
photos.value = photosInPreferences;
@@ -207,11 +207,11 @@ export const usePhotoGallery = () => {
207207
const photosInPreferences = photoList.value ? JSON.parse(photoList.value) : [];
208208

209209
for (const photo of photosInPreferences) {
210-
const readFile = await Filesystem.readFile({
210+
const file = await Filesystem.readFile({
211211
path: photo.filepath,
212212
directory: Directory.Data,
213213
});
214-
photo.webviewPath = `data:image/jpeg;base64,${readFile.data}`;
214+
photo.webviewPath = `data:image/jpeg;base64,${file.data}`;
215215
}
216216

217217
photos.value = photosInPreferences;
@@ -305,11 +305,11 @@ export const usePhotoGallery = () => {
305305
const photosInPreferences = photoList.value ? JSON.parse(photoList.value) : [];
306306

307307
for (const photo of photosInPreferences) {
308-
const readFile = await Filesystem.readFile({
308+
const file = await Filesystem.readFile({
309309
path: photo.filepath,
310310
directory: Directory.Data,
311311
});
312-
photo.webviewPath = `data:image/jpeg;base64,${readFile.data}`;
312+
photo.webviewPath = `data:image/jpeg;base64,${file.data}`;
313313
}
314314

315315
photos.value = photosInPreferences;

docs/vue/your-first-app/5-adding-mobile.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ const savePicture = async (photo: Photo, fileName: string): Promise<UserPhoto> =
4747
// CHANGE: Add platform check
4848
// "hybrid" will detect mobile - iOS or Android
4949
if (isPlatform('hybrid')) {
50-
const readFile = await Filesystem.readFile({
50+
const file = await Filesystem.readFile({
5151
path: photo.path!,
5252
});
53-
base64Data = readFile.data;
53+
base64Data = typeof file.data === 'string' ? file.data : await file.data.text();
5454
} else {
5555
// Fetch the photo, read as a blob, then convert to base64 format
5656
const response = await fetch(photo.webPath!);
@@ -98,10 +98,10 @@ const savePicture = async (photo: Photo, fileName: string): Promise<UserPhoto> =
9898
// CHANGE: Add platform check
9999
// "hybrid" will detect mobile - iOS or Android
100100
if (isPlatform('hybrid')) {
101-
const readFile = await Filesystem.readFile({
101+
const file = await Filesystem.readFile({
102102
path: photo.path!,
103103
});
104-
base64Data = readFile.data;
104+
base64Data = typeof file.data === 'string' ? file.data : await file.data.text();
105105
} else {
106106
// Fetch the photo, read as a blob, then convert to base64 format
107107
const response = await fetch(photo.webPath!);
@@ -145,12 +145,12 @@ const loadSaved = async () => {
145145
// If running on the web...
146146
if (!isPlatform('hybrid')) {
147147
for (const photo of photosInPreferences) {
148-
const readFile = await Filesystem.readFile({
148+
const file = await Filesystem.readFile({
149149
path: photo.filepath,
150150
directory: Directory.Data,
151151
});
152152
// Web platform only: Load the photo as base64 data
153-
photo.webviewPath = `data:image/jpeg;base64,${readFile.data}`;
153+
photo.webviewPath = `data:image/jpeg;base64,${file.data}`;
154154
}
155155
}
156156

@@ -195,10 +195,10 @@ export const usePhotoGallery = () => {
195195
let base64Data: string | Blob;
196196
// "hybrid" will detect mobile - iOS or Android
197197
if (isPlatform('hybrid')) {
198-
const readFile = await Filesystem.readFile({
198+
const file = await Filesystem.readFile({
199199
path: photo.path!,
200200
});
201-
base64Data = readFile.data;
201+
base64Data = typeof file.data === 'string' ? file.data : await file.data.text();
202202
} else {
203203
// Fetch the photo, read as a blob, then convert to base64 format
204204
const response = await fetch(photo.webPath!);
@@ -253,12 +253,12 @@ export const usePhotoGallery = () => {
253253
// If running on the web...
254254
if (!isPlatform('hybrid')) {
255255
for (const photo of photosInPreferences) {
256-
const readFile = await Filesystem.readFile({
256+
const file = await Filesystem.readFile({
257257
path: photo.filepath,
258258
directory: Directory.Data,
259259
});
260260
// Web platform only: Load the photo as base64 data
261-
photo.webviewPath = `data:image/jpeg;base64,${readFile.data}`;
261+
photo.webviewPath = `data:image/jpeg;base64,${file.data}`;
262262
}
263263
}
264264

0 commit comments

Comments
 (0)