upd: upload gambar

Deskripsi:
- upload gambar create banner
- nb : susahhh, blm selesai

No Issues
This commit is contained in:
amel
2025-05-14 17:36:23 +08:00
parent 6b3de4d6b2
commit a877eec078
4 changed files with 11 additions and 9 deletions

View File

@@ -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 (

BIN
bun.lockb

Binary file not shown.

View File

@@ -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 }) => {

View File

@@ -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",