Skip to content

Commit

Permalink
fix: camera #70
Browse files Browse the repository at this point in the history
  • Loading branch information
11t518s committed Apr 4, 2022
1 parent f9bab72 commit 4adcf33
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions components/camera/CameraAndGallery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
});
};
Expand All @@ -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);
});

Expand Down

0 comments on commit 4adcf33

Please sign in to comment.