upd: upload gambar
Deskripsi: - upload gambar create banner - nb : susahhh, blm selesai No Issues
This commit is contained in:
@@ -9,7 +9,7 @@ import { Entypo } from "@expo/vector-icons";
|
||||
import * as ImagePicker from 'expo-image-picker';
|
||||
import { router, Stack } from "expo-router";
|
||||
import { useState } from "react";
|
||||
import { Image, Pressable, SafeAreaView, ScrollView, Text, View } from "react-native";
|
||||
import { Image, Platform, Pressable, SafeAreaView, ScrollView, Text, View } from "react-native";
|
||||
import { useDispatch } from "react-redux";
|
||||
|
||||
export default function CreateBanner() {
|
||||
@@ -34,14 +34,16 @@ export default function CreateBanner() {
|
||||
}
|
||||
};
|
||||
|
||||
console.log(imgForm)
|
||||
|
||||
const handleCreateEntity = async () => {
|
||||
const hasil = await decryptToken(String(token?.current))
|
||||
const fd = new FormData()
|
||||
fd.append("file", JSON.stringify({
|
||||
uri: imgForm.uri,
|
||||
type: 'image/jpeg', // or response.assets[0].type
|
||||
type: imgForm.mimeType,
|
||||
name: imgForm.fileName,
|
||||
size: imgForm.fileSize,
|
||||
}))
|
||||
fd.append("data", JSON.stringify(
|
||||
{
|
||||
@@ -50,7 +52,8 @@ export default function CreateBanner() {
|
||||
}
|
||||
))
|
||||
const createdEntity = await apiCreateBanner(fd);
|
||||
dispatch(addEntity(createdEntity));
|
||||
// console.log('cliene',createdEntity)
|
||||
// dispatch(addEntity(createdEntity));
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
10
lib/api.ts
10
lib/api.ts
@@ -32,16 +32,14 @@ export const apiGetBanner = async ({ user }: { user: string }) => {
|
||||
|
||||
|
||||
export const apiCreateBanner = async (data: FormData) => {
|
||||
await api.post('/banner', data, {
|
||||
console.log('jalan', data)
|
||||
const response = await api.post('mobile/banner', data, {
|
||||
headers: {
|
||||
'Content-Type': 'multipart/form-data',
|
||||
},
|
||||
}).then(response => {
|
||||
return response.data;
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error:', error);
|
||||
});
|
||||
console.log('api',response.data)
|
||||
return response.data;
|
||||
};
|
||||
|
||||
export const apiGetDataHome = async ({ cat, user }: { cat: 'kegiatan' | 'division' | 'progress' | 'dokumen' | 'event' | 'discussion' | 'header' | 'check-late-project', user: string }) => {
|
||||
|
||||
@@ -45,6 +45,7 @@
|
||||
"react-dom": "18.3.1",
|
||||
"react-native": "0.76.7",
|
||||
"react-native-confirmation-code-field": "^7.4.0",
|
||||
"react-native-fs": "^2.20.0",
|
||||
"react-native-gesture-handler": "~2.20.2",
|
||||
"react-native-gifted-charts": "^1.4.57",
|
||||
"react-native-modal": "^14.0.0-rc.1",
|
||||
|
||||
Reference in New Issue
Block a user