Skip to content

Commit 8e9723c

Browse files
committed
fix!(upload): assets now upload without failure
1 parent 1aaa583 commit 8e9723c

5 files changed

Lines changed: 745 additions & 288 deletions

File tree

app.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"expo": {
33
"name": "Flux",
44
"slug": "flux",
5-
"version": "1.5.17",
5+
"version": "1.5.18",
66
"orientation": "portrait",
77
"icon": "./assets/images/icon.png",
88
"scheme": "flux",

app/editor/[path].tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import axios from 'axios';
44
import { Buffer } from 'buffer';
55
import * as Clipboard from 'expo-clipboard';
66
import * as DocumentPicker from 'expo-document-picker';
7+
import * as FileSystem from 'expo-file-system';
78
import * as Haptics from 'expo-haptics';
89
import { Image } from 'expo-image';
910
import * as ImageManipulator from 'expo-image-manipulator';
@@ -1277,13 +1278,7 @@ export default function Editor() {
12771278
const token = await SecureStore.getItemAsync('github_access_token');
12781279
if (!token) throw new Error('Not authenticated');
12791280

1280-
const response = await fetch(lastPickedUri);
1281-
const blob = await response.blob();
1282-
const reader = new FileReader();
1283-
const base64Data = await new Promise<string>((resolve) => {
1284-
reader.onloadend = () => resolve((reader.result as string).split(',')[1]);
1285-
reader.readAsDataURL(blob);
1286-
});
1281+
const base64Data = await new FileSystem.File(lastPickedUri).base64();
12871282

12881283
// Check if exists to get SHA (for overwrite)
12891284
let assetSha = undefined;

app/files.tsx

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import AsyncStorage from '@react-native-async-storage/async-storage';
33
import axios from 'axios';
44
import { Buffer } from 'buffer';
55
import * as DocumentPicker from 'expo-document-picker';
6+
import * as FileSystem from 'expo-file-system';
67
import * as Haptics from 'expo-haptics';
78
import { Image } from 'expo-image';
89
import * as ImageManipulator from 'expo-image-manipulator';
@@ -1194,17 +1195,7 @@ export default function Files() {
11941195
const fullAssetsPath = [cleanStatic, cleanAssets].filter(Boolean).join('/');
11951196
const newPath = `${fullAssetsPath}/${finalName}`.replace(/^\/+/, '').replace(/\/+/g, '/');
11961197

1197-
const resp = await fetch(lastPickedUri);
1198-
const blob = await resp.blob();
1199-
const base64: string = await new Promise((resolve, reject) => {
1200-
const reader = new FileReader();
1201-
reader.onload = () => {
1202-
const res = reader.result as string;
1203-
resolve(res.split(',')[1]);
1204-
};
1205-
reader.onerror = reject;
1206-
reader.readAsDataURL(blob);
1207-
});
1198+
const base64 = await new FileSystem.File(lastPickedUri).base64();
12081199

12091200
await axios.put(`https://api.github.com/repos/${repoPath}/contents/${newPath}`, {
12101201
message: `add!(assets): uploaded asset ${finalName}`,

0 commit comments

Comments
 (0)