isMainImage przekazywane na Backend
This commit is contained in:
@@ -39,8 +39,14 @@ export async function createNotice(notice) {
|
||||
});
|
||||
|
||||
if (response.data.noticeId !== null) {
|
||||
for (const imageUri of notice.image) {
|
||||
await uploadImage(response.data.noticeId, imageUri);
|
||||
for (const image of notice.image) {
|
||||
console.log("image", image);
|
||||
if(notice.image.indexOf(image) === 0) {
|
||||
console.log("Image is first:", image);
|
||||
await uploadImage(response.data.noticeId, image, true);
|
||||
}
|
||||
console.log("image", image);
|
||||
await uploadImage(response.data.noticeId, image, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,7 +100,7 @@ export async function getAllImagesByNoticeId(noticeId) {
|
||||
}
|
||||
}
|
||||
|
||||
export const uploadImage = async (noticeId, imageUri) => {
|
||||
export const uploadImage = async (noticeId, imageObj, isFirst) => {
|
||||
const { token } = useAuthStore.getState();
|
||||
const headers = {
|
||||
...(token ? { Authorization: `Bearer ${token}` } : {}),
|
||||
@@ -102,20 +108,20 @@ export const uploadImage = async (noticeId, imageUri) => {
|
||||
};
|
||||
const formData = new FormData();
|
||||
|
||||
const filename = imageUri.split("/").pop();
|
||||
const filename = imageObj.split("/").pop();
|
||||
|
||||
const match = /\.(\w+)$/.exec(filename);
|
||||
const type = match ? `image/${match[1]}` : "image/jpeg";
|
||||
|
||||
formData.append("file", {
|
||||
uri: imageUri,
|
||||
uri: imageObj,
|
||||
name: filename,
|
||||
type: type,
|
||||
});
|
||||
|
||||
try {
|
||||
const response = await axios.post(
|
||||
`${API_URL}/images/upload/${noticeId}`,
|
||||
`${API_URL}/images/upload/${noticeId}?isMainImage=${isFirst}`,
|
||||
formData,
|
||||
{
|
||||
headers: headers,
|
||||
@@ -124,7 +130,7 @@ export const uploadImage = async (noticeId, imageUri) => {
|
||||
console.info("Upload successful:", response.data);
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
console.log("imageURI:", imageUri);
|
||||
console.log("imageURI:", imageObj);
|
||||
|
||||
console.error(
|
||||
"Error uploading image:",
|
||||
|
||||
Reference in New Issue
Block a user