Skip to content

Commit

Permalink
fix post crash on Android
Browse files Browse the repository at this point in the history
  • Loading branch information
Spec-DY committed Dec 2, 2024
1 parent 364e080 commit e75b41d
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions firebase/services/postService.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
deleteObject,
} from "firebase/storage";
import * as FileSystem from "expo-file-system";
import { Platform } from "react-native";

export const postService = {
async createPost(userId, { imageUri, location, caption }) {
Expand All @@ -34,11 +35,20 @@ export const postService = {
throw new Error("Image file does not exist");
}

const response = await fetch(
`data:image/jpeg;base64,${await FileSystem.readAsStringAsync(imageUri, {
encoding: FileSystem.EncodingType.Base64,
})}`
);
let response;
if (Platform.OS === "ios") {
response = await fetch(
`data:image/jpeg;base64,${await FileSystem.readAsStringAsync(
imageUri,
{
encoding: FileSystem.EncodingType.Base64,
}
)}`
);
} else {
response = await fetch(imageUri);
}

const blob = await response.blob();

// Upload image to Firebase Storage
Expand Down

0 comments on commit e75b41d

Please sign in to comment.