forked from camilasandovals/DevCon2024
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpost.js
34 lines (31 loc) · 843 Bytes
/
post.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import * as FileSystem from "expo-file-system";
import { Platform } from "react-native";
export const uploadPicture = async (imageUri) => {
try {
const fileBlob = await FileSystem.readAsStringAsync(imageUri, {
encoding: FileSystem.EncodingType.Base64,
});
const requestBody = new FormData();
requestBody.append("image", {
name: "upload.jpg",
type: "image/jpg",
uri:
Platform.OS === "ios" ? `data:image/jpg;base64,${fileBlob}` : imageUri,
});
const response = await fetch(
"",
{
method: "POST",
headers: {
"Content-Type": "multipart/form-data",
},
body: requestBody,
}
);
const data = await response.json();
return data;
} catch (error) {
console.error("API call failed:", error);
return null;
}
};