uplodowanie wszystkich zdjęć które są wybrane przy dodawaniu produktu

This commit is contained in:
2025-05-05 15:01:25 +02:00
parent 1a8fe7bb1d
commit 845a2e9593
4 changed files with 1483 additions and 192 deletions

View File

@@ -2,6 +2,7 @@ import axios from "axios";
import FormData from 'form-data'
const API_URL = "https://testowe.zikor.pl/api/v1";
// const API_URL = "http://172.20.10.2:8080/api/v1";
export async function listNotices() {
@@ -35,7 +36,10 @@ export async function createNotice(notice) {
// console.log("Image url: ", notice.image)
if (response.data.noticeId !== null) {
uploadImage(response.data.noticeId, notice.image);
notice.image.forEach(imageUri => {
uploadImage(response.data.noticeId, imageUri);
});
// uploadImage(response.data.noticeId, notice.image);
}
} catch (error) {
@@ -63,18 +67,15 @@ export async function getImageByNoticeId(noticeId) {
export const uploadImage = async (noticeId, imageUri) => {
console.log("Started upload image");
console.log(imageUri);
// Utwórz obiekt FormData
const formData = new FormData();
// Zdobądź nazwę pliku z URI
const filename = imageUri.split('/').pop();
// Określ typ MIME (możesz dostosować lub wykrywać dynamicznie)
const match = /\.(\w+)$/.exec(filename);
const type = match ? `image/${match[1]}` : 'image/jpeg';
// Dodaj plik do FormData w formacie akceptowanym przez serwer
formData.append('file', {
uri: imageUri,
name: filename,