This commit is contained in:
Patryk
2025-06-09 20:59:46 +02:00
2 changed files with 7 additions and 5 deletions

View File

@@ -99,6 +99,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();
@@ -107,7 +112,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,
});
@@ -117,9 +122,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);

View File

@@ -94,7 +94,6 @@ export default function CreateNotice() {
try {
const result = await addNotice({
title: title,
clientId: 1,
description: description,
price: price,
category: category,