From 4adcf3338959647c616eb749348e0d7f77f153b1 Mon Sep 17 00:00:00 2001 From: 11t518s <11t518s20161759@gmail.com> Date: Mon, 4 Apr 2022 23:00:51 +0900 Subject: [PATCH] fix: camera #70 --- components/camera/CameraAndGallery.tsx | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/components/camera/CameraAndGallery.tsx b/components/camera/CameraAndGallery.tsx index 5ccd00f..c50cbc3 100644 --- a/components/camera/CameraAndGallery.tsx +++ b/components/camera/CameraAndGallery.tsx @@ -14,6 +14,26 @@ interface IProps { function CameraAndGallery({ setOnModal, onModal }: IProps) { const checkListContext = useContext(checkListCtx); + const onPostCameraDataHandler = async (image: any) => { + const imageData = new FormData(); + + imageData.append('image', { + uri: Platform.OS === 'android' ? image.path : image.path.replace('file://', ''), + type: image.mime, + name: image.filename, + }); + + await axios + .post(`/api/check-list/${checkListContext?.checkListId}/image`, imageData) + .then((e) => { + console.log('t'); + console.log(e); + }) + .catch((e) => { + console.log('c'); + console.log(e); + }); + }; const onPostImageDataHandler = async (images: any) => { const imageData = new FormData(); @@ -28,9 +48,11 @@ function CameraAndGallery({ setOnModal, onModal }: IProps) { await axios .post(`/api/check-list/${checkListContext?.checkListId}/image`, imageData) .then((e) => { + console.log('t'); console.log(e); }) .catch((e) => { + console.log('c'); console.log(e); }); }; @@ -46,8 +68,8 @@ function CameraAndGallery({ setOnModal, onModal }: IProps) { const onCamera = () => ImagePicker.openCamera({ cropping: true, - }).then((images: any) => { - onPostImageDataHandler(images); + }).then((image: any) => { + onPostCameraDataHandler(image); setOnModal(!onModal); });