diff --git a/ArtisanConnect/api/notices.jsx b/ArtisanConnect/api/notices.jsx index 222cdb8..6ede845 100644 --- a/ArtisanConnect/api/notices.jsx +++ b/ArtisanConnect/api/notices.jsx @@ -95,6 +95,11 @@ export async function getAllImagesByNoticeId(noticeId) { } export const uploadImage = async (noticeId, imageUri) => { + const { token } = useAuthStore.getState(); + const headers = { + ...(token ? { Authorization: `Bearer ${token}` } : {}), + 'Content-Type': 'multipart/form-data' + }; const formData = new FormData(); const filename = imageUri.split("/").pop(); @@ -103,7 +108,7 @@ export const uploadImage = async (noticeId, imageUri) => { const type = match ? `image/${match[1]}` : "image/jpeg"; formData.append("file", { - uri: imageUri, + uri: imageUri.uri, name: filename, type: type, }); @@ -113,9 +118,7 @@ export const uploadImage = async (noticeId, imageUri) => { `${API_URL}/images/upload/${noticeId}`, formData, { - headers: { - "Content-Type": "multipart/form-data", - }, + headers: headers, } ); console.info("Upload successful:", response.data); diff --git a/ArtisanConnect/app/(tabs)/notice/create.jsx b/ArtisanConnect/app/(tabs)/notice/create.jsx index 33057aa..89d9dad 100644 --- a/ArtisanConnect/app/(tabs)/notice/create.jsx +++ b/ArtisanConnect/app/(tabs)/notice/create.jsx @@ -94,7 +94,6 @@ export default function CreateNotice() { try { const result = await addNotice({ title: title, - clientId: 1, description: description, price: price, category: category,