wysyłanie jednego zdjęcie nie działało
This commit is contained in:
@@ -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);
|
||||||
|
|||||||
@@ -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,
|
||||||
|
|||||||
Reference in New Issue
Block a user