add: file upload logic

v0.4
rrr-marble 3 years ago
parent b1a5adfdf3
commit 47caa8cd26

@ -76,7 +76,7 @@ export default {
}, },
getPreviewPath(){ getPreviewPath(){
for (let extension of ["jpg", "png", "bmp"]) { for (let extension of ["jpg", "png", "bmp"]) {
const path = `${this.baseURL}/static/previews/${this.itemDetails.fadr}+/${this.itemDetails.internal_id}.${extension}` const path = `/static/previews/${this.itemDetails.fadr}+/${this.itemDetails.internal_id}.${extension}`
fetch(path, {method: 'HEAD'}) fetch(path, {method: 'HEAD'})
.then(resp => { .then(resp => {
if (resp.status === 200) { if (resp.status === 200) {
@ -86,7 +86,7 @@ export default {
.catch(e => { .catch(e => {
// 404 are expected here, so ignore it // 404 are expected here, so ignore it
if (e.status !== 404){ if (e.status !== 404){
//console.log(e) console.log(e)
} }
}) })
} }

@ -2,7 +2,7 @@
<div> <div>
<h1 style="font-size: 3rem; margin: 1rem;">Upload</h1> <h1 style="font-size: 3rem; margin: 1rem;">Upload</h1>
<div class="upload-dashboard"> <div class="upload-dashboard">
<va-file-upload dropzone></va-file-upload> <va-file-upload dropzone type="single" @file-added="handleFile"></va-file-upload>
</div> </div>
</div> </div>
</template> </template>
@ -10,7 +10,25 @@
<script> <script>
export default { export default {
name: "upload-screen" name: "upload-screen",
data() {
return {
response: {},
showModal: false,
}
},
methods: {
handleFile(files) {
const formData = new FormData();
formData.append('file', files[0], files[0].name);
fetch("/api/v1/items/", {method: 'POST', body: formData})
.then(res => res.json())
.then(data => this.response = data)
.catch((e) => console.log(e))
.then(()=>console.log(this.response))
}
},
} }
</script> </script>

Loading…
Cancel
Save