Generic uploadFile
This commit is contained in:
parent
5fad00dbe6
commit
7074fb86c3
@ -10,7 +10,7 @@ export function selectFile(arn: AnimeNotifier, button: HTMLButtonElement) {
|
|||||||
let file = input.files[0]
|
let file = input.files[0]
|
||||||
|
|
||||||
previewImage(file, preview)
|
previewImage(file, preview)
|
||||||
uploadImage(file)
|
uploadFile(file, "/api/upload/avatar")
|
||||||
}
|
}
|
||||||
|
|
||||||
input.click()
|
input.click()
|
||||||
@ -32,12 +32,12 @@ function previewImage(file: File, preview: HTMLImageElement) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Upload image
|
// Upload file
|
||||||
function uploadImage(file: File) {
|
function uploadFile(file: File, endpoint: string) {
|
||||||
let reader = new FileReader()
|
let reader = new FileReader()
|
||||||
|
|
||||||
reader.onloadend = async () => {
|
reader.onloadend = async () => {
|
||||||
await fetch("/api/upload/avatar", {
|
await fetch(endpoint, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
credentials: "include",
|
credentials: "include",
|
||||||
headers: {
|
headers: {
|
||||||
|
Loading…
Reference in New Issue
Block a user