I'm trying to implement file upload functionality using Vue.js version 3.
Although I have successfully imported ref
, I am unsure how to utilize it for retrieving file data?
FileUploadTest.vue
<template>
<h1>File Upload</h1>
<div class="container">
<div>
<label>File
<input type="file" id="file" ref="file" v-on:change="onChangeFileUpload()"/>
</label>
<button v-on:click="submitForm()">Upload</button>
</div>
</div>
</template>
<script src="./FileUploadTest.ts" lang="ts"></script>
FileUploadTest.ts
import { Options, Vue } from "vue-class-component";
import { ref } from 'vue';
import axios from "../../axios/index";
@Options({})
export default class FileUploadTest extends Vue {
protected file: any;
submitForm() {
const formData = new FormData();
formData.append('bytes', this.file);
axios.post('https://localhost:44313/api/app/file/save',
formData,
{
headers: {
'Content-Type': 'multipart/form-data'
}
}
).then(function (data) {
console.log(data.data);
})
.catch(function () {
console.log('FAILURE!!');
});
}
onChangeFileUpload() {
debugger;
this.file = ref(["file"]).value;
}
};
The issue I am facing is that the actual file content is not being stored in the this.file variable
this.file = ref(["file"]).value;