added test image upload

This commit is contained in:
2024-04-20 17:36:18 +07:00
parent 4dbb67d5fc
commit 4a11cf0f94
4 changed files with 66 additions and 1 deletions

45
src/views/UploadImage.vue Normal file
View File

@@ -0,0 +1,45 @@
<template>
<div>
<input
type="file"
@change="onFileChanged($event)"
accept="image/*"
capture
/>
<button @click="uploadImage()">Upload</button>
</div>
</template>
<script>
import { client } from "@/utils/trpc";
import { createFormData } from "@/utils/fileUpload";
export default {
data: () => ({
file: null,
}),
methods: {
onFileChanged(event) {
const file = event.target.files[0];
this.file = file;
},
async uploadImage() {
if (!this.file) {
return;
}
let request = await client.user.requestChangeImage.mutate({
imageName: this.file.name,
contentType: this.file.type,
});
let formData = createFormData(request, this.file);
await fetch(request.postURL, {
method: "POST",
body: formData,
}).then(() => {
client.user.confirmChangeImage.mutate();
});
console.log("done");
},
},
};
</script>
<style></style>