wysyłanie jednego zdjęcie nie działało

This commit is contained in:
2025-06-09 20:35:56 +02:00
parent 77c3a694f8
commit b34ce7fd20
2 changed files with 7 additions and 5 deletions

View File

@@ -95,6 +95,11 @@ export async function getAllImagesByNoticeId(noticeId) {
} }
export const uploadImage = async (noticeId, imageUri) => { 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 formData = new FormData();
const filename = imageUri.split("/").pop(); const filename = imageUri.split("/").pop();
@@ -103,7 +108,7 @@ export const uploadImage = async (noticeId, imageUri) => {
const type = match ? `image/${match[1]}` : "image/jpeg"; const type = match ? `image/${match[1]}` : "image/jpeg";
formData.append("file", { formData.append("file", {
uri: imageUri, uri: imageUri.uri,
name: filename, name: filename,
type: type, type: type,
}); });
@@ -113,9 +118,7 @@ export const uploadImage = async (noticeId, imageUri) => {
`${API_URL}/images/upload/${noticeId}`, `${API_URL}/images/upload/${noticeId}`,
formData, formData,
{ {
headers: { headers: headers,
"Content-Type": "multipart/form-data",
},
} }
); );
console.info("Upload successful:", response.data); console.info("Upload successful:", response.data);

View File

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