uplodowanie wszystkich zdjęć które są wybrane przy dodawaniu produktu
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user