uploading image from bank working

This commit is contained in:
isUnknown 2024-10-15 14:51:12 +02:00
parent 9df71b4949
commit 97262303fc
4 changed files with 116 additions and 76 deletions

View file

@ -8,7 +8,7 @@
style="--row-gap: var(--space-8)"
>
<AccordionPanel
v-for="(image, index) in activeTab.selectedImages"
v-for="(image, index) in images"
:key="index + 1"
:value="index"
class="w-full | bg-white | rounded-xl | p-12 pt-8"
@ -108,11 +108,16 @@ import { usePageStore } from "../../../../stores/page";
import StringUtils from "../../../../utils/string";
import { storeToRefs } from "pinia";
import { useAddImagesModalStore } from "../../../../stores/addImagesModal";
import { computed } from "vue";
const { page } = storeToRefs(usePageStore());
const { activeTab } = storeToRefs(useAddImagesModalStore());
const images = computed(() => {
return activeTab.value.selectedImages;
});
// function saveTags(image) {
// const headers = {
// method: "POST",
@ -164,15 +169,15 @@ const { activeTab } = storeToRefs(useAddImagesModalStore());
function addImagesToBrief() {
const formData = new FormData();
const blobPromises = images.map((item) => {
const blobPromises = images.value.map((item) => {
if (item.url.startsWith("blob:")) {
return fetch(item.url)
.then((response) => response.blob())
.then((blob) => {
formData.append("images[]", blob, item.name);
formData.append("images[]", blob, JSON.stringify(item));
});
} else {
formData.append("imageUris[]", item.url);
formData.append("imageUris[]", JSON.stringify(item));
return Promise.resolve();
}
});
@ -183,7 +188,10 @@ function addImagesToBrief() {
body: formData,
})
.then((res) => res.json())
.then((json) => (page.value.images = json.images))
.then((json) => {
page.value.images = json.images;
console.log(json);
})
.catch((error) => console.error("Error:", error));
});
}

View file

@ -21,6 +21,4 @@ const { tabs } = storeToRefs(useAddImagesModalStore());
const tab = computed(() => {
return tabs.value.find((tab) => tab.id === "materials");
});
console.log(ArrayUtils);
</script>