From 76ad709e0afed734c4331ddb8de91745a541a67d Mon Sep 17 00:00:00 2001 From: "Adam T. Carpenter" Date: Wed, 4 Nov 2020 08:59:41 -0500 Subject: basic photo upload working completely --- .../src/components/admin/ProductEditCard.vue | 43 +++++++++++++++------- 1 file changed, 30 insertions(+), 13 deletions(-) (limited to 'iridescence/src/components') diff --git a/iridescence/src/components/admin/ProductEditCard.vue b/iridescence/src/components/admin/ProductEditCard.vue index 8d1eb3d..238c975 100644 --- a/iridescence/src/components/admin/ProductEditCard.vue +++ b/iridescence/src/components/admin/ProductEditCard.vue @@ -214,27 +214,44 @@ export default { this.newProduct.quantity += amount; } }, - previewFiles(event) { + async previewFiles(event) { let file = event.target.files[0]; if (!file) { return; } - let reader = new FileReader(); + const fd = new FormData(); + fd.append(file.name, file); - reader.onprogress = e => { - if (e && e.lengthComputable) { - this.fileProgress = parseInt((e.loaded / e.total) * 100, 10); - } - }; + const response = await fetch("http://localhost:8000/photos", { + method: "POST", + body: fd + }); + console.log(response); + //let reader = new FileReader(); + + //reader.onprogress = e => { + // if (e && e.lengthComputable) { + // this.fileProgress = parseInt((e.loaded / e.total) * 100, 10); + // } + //}; + + //reader.onloadend = e => { + // this.fileProgress = 100; + // this.newProduct.imgPath = file.name; + + // let formData = new FormData(); + // formData.append(file.name, e.target.result); - reader.onloadend = e => { - console.log(e.target.result); - this.fileProgress = 100; - this.newProduct.imgPath = file.name; - }; + // fetch("http://localhost:8000/photos", { + // method: "POST", + // body: formData + // }).then(r => { + // console.log(r); + // }); + //}; - reader.readAsDataURL(file); + //reader.readAsBinaryString(file); } } }; -- cgit v1.2.3