added test image upload
This commit is contained in:
45
src/views/UploadImage.vue
Normal file
45
src/views/UploadImage.vue
Normal 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>
|
||||
Reference in New Issue
Block a user