upd: upload gambar
Deskripsi: - test upload gambar di login NO Issues
This commit is contained in:
@@ -2,16 +2,40 @@ import Styles from "@/constants/Styles"
|
||||
import { apiCheckPhoneLogin, apiSendOtp } from "@/lib/api"
|
||||
import AsyncStorage from "@react-native-async-storage/async-storage"
|
||||
import { useState } from "react"
|
||||
import { Image, Text, ToastAndroid, View } from "react-native"
|
||||
import { Button, Image, Text, ToastAndroid, View } from "react-native"
|
||||
import { ButtonForm } from "../buttonForm"
|
||||
import { InputForm } from "../inputForm"
|
||||
import ModalLoading from "../modalLoading"
|
||||
import * as ImagePicker from 'expo-image-picker';
|
||||
|
||||
|
||||
type Props = {
|
||||
onValidate: ({ phone, otp }: { phone: string, otp: number }) => void
|
||||
}
|
||||
|
||||
async function handleUpload() {
|
||||
console.log('handleUpload')
|
||||
const result = await ImagePicker.launchImageLibraryAsync({
|
||||
mediaTypes: ImagePicker.MediaTypeOptions.Images,
|
||||
allowsEditing: false,
|
||||
aspect: [4, 3],
|
||||
quality: 1,
|
||||
});
|
||||
|
||||
const formData = new FormData()
|
||||
formData.append('file', {
|
||||
uri: result.assets![0].uri,
|
||||
type: "image/jpeg",
|
||||
name: "bip.png",
|
||||
} as any)
|
||||
|
||||
const res = await fetch("https://amal.wibudev.com/api/v2/test", {
|
||||
method: "POST",
|
||||
body: formData,
|
||||
});
|
||||
console.log(await res.json())
|
||||
}
|
||||
|
||||
export default function ViewLogin({ onValidate }: Props) {
|
||||
const [loadingLogin, setLoadingLogin] = useState(false)
|
||||
const [disableLogin, setDisableLogin] = useState(true)
|
||||
@@ -42,6 +66,7 @@ export default function ViewLogin({ onValidate }: Props) {
|
||||
return (
|
||||
<>
|
||||
<View style={Styles.wrapLogin} >
|
||||
<Button title="Upload" onPress={handleUpload} />
|
||||
<View style={{ alignItems: "center", marginVertical: 50 }}>
|
||||
<Image
|
||||
source={require("../../assets/images/splash-icon.png")}
|
||||
|
||||
Reference in New Issue
Block a user